views:

1319

answers:

3

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?

+2  A: 

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
+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
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!
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
A: 

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
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.
+1  A: 

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
+1, By coincidence I was just on my way to edit my answer having read up on the archiver a bit for this question: http://stackoverflow.com/questions/1510071/
Rich Seller
Well, I just discovered this while digging on the archiver for the manifest question too :) If you want to update your answer, just let me know.
Pascal Thivent
I updated my answer and recommended the OP accept yours, then some bugger downvoted me. Charming
Rich Seller
Thanks, very noble from you. And just no comment about the downvote.
Pascal Thivent