21

Using Maven war plugin, I generate WAR which includes following directory:

META-INF
-- maven
   -- com.abc.def
      -- myServlet
         -- pom.xml
         -- pom.properties

In release, I want to exclude this maven directory. How can I do that?

I tried latest maven-war-plugin (2.1-beta-1), it has configuration "packagingExcludes", but it doesn't work as I wish.

Any suggestions?

user179080
  • 213
  • 1
  • 2
  • 5

4 Answers4

44

I'm not sure but I think that the Maven Archiver (which is mainly used by plugins to handle packaging) can be configured to achieve this.

About the <addMavenDescriptor> element, the Maven Archiver Reference says:

Whether the generated archive will contain these two Maven files:

  • The pom file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.xml
  • A pom.properties file, located in the archive in META-INF/maven/${groupId}/${artifactId}/pom.properties

The default value is true.

So a pom configured like this should do the trick:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0</version>
        <configuration>
          <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
          </archive>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
14

Using the standard Maven packaging you can't omit the file to my knowledge. It is possible however to use the maven-assembly-plugin to construct the war, in this case you have much finer grained control over the contents of the artifact, and can omit the pom.xml.

However I have personally found it useful to keep the pom.xml for diagnostic purposes. It can be handy to know what was used to build and assemble the war when trying to figure out what is wrong with your app.

Update: in a bizarre bit of synchronicity to Pascal's answer, I've just been reading up on the Archiver reference and it appears that this can be done by setting the addMavenDescriptor property to false. Personally I would still avoid doing this for reasons given above. But you may want to change your acceptance to Pascal's answer.

Rich Seller
  • 83,208
  • 23
  • 172
  • 177
  • +1 Thanks Rich for your insightful comments on all Maven related questions ! :-) I learned on all your answers. On this one, I was especially interested in the second paragraph, more related to best-practice and hard-learned experience. – KLE Sep 25 '09 at 15:05
  • I agree with the diagnostic purpose. However, we have some special customization in pom.xml, which reveals file structure on build machine. Of course, we do not want to expose that information to clients or any user. I will try the maven-assembly-plugin. Thanks! – user179080 Sep 25 '09 at 15:27
  • 1
    I tend to agree with Rich (I find it handy too to keep these files) but I think that the Maven Archiver provide a configuration option allowing to avoid the packaging of these files. See my answer below. – Pascal Thivent Oct 02 '09 at 17:17
  • META-INF/MANIFEST.MF (http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html) is the place to put all version and built information required to track down the revision of a JAR. – Risadinha Sep 18 '13 at 16:35
  • @Risadinha I don't think MANIFEST.MF has anything to do with this answer – Zero3 Mar 19 '15 at 21:33
  • I don't remember my train of thought in 2013 but I suspect I wanted to remind that there is already a place in the JAR where information on the build was originally meant to be stored: the Manifest. Adding the pom.xml *might be* redundant if you make use of all of Manifest's features. – Risadinha Mar 20 '15 at 08:22
0

Putting a META-INF folder in a resources directory or in the root of your source directory will destroy the META-INF content created by Maven. For WAR files, putting a META-INF in your web content directory will do the same.

Adding other content to that custom META-INF will override what maven would create.

sal
  • 23,373
  • 15
  • 66
  • 85
  • I put a META-INF folder in resources directory, not only maven/ directory got inserted, but also my MANIFEST.MF file got override. I am using maven-war-plugin, version 2.0. I tried version 2.1.beta-1, still the same. – user179080 Sep 25 '09 at 20:46
0
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <warSourceExcludes>pom.xml</warSourceExcludes>
    </configuration>
</plugin>

or

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <warSourceExcludes>here/there/everywhere/a/pom.xml</warSourceExcludes>
    </configuration>
</plugin>
user3731460
  • 334
  • 4
  • 14