Question

The Maven WAR plugin has two configuration options: warSourceExcludes and packagingExcludes. There is some documentation on packagingExcludes, saying that:

It is possible to include or exclude certain files from the WAR file, by using the <packagingIncludes> and <packagingExcludes> configuration parameters.

However, I find it very difficult to find information on warSourceExcludes.

What is the difference between these two configuration options?

I'm using Maven 3.1.1 and the WAR plugin is version 2.4

Was it helpful?

Solution

warSourceExcludes: The comma separated list of tokens to exclude when copying the content of the warSourceDirectory.


packagingExcludes: The comma separated list of tokens to exclude from the WAR before packaging.

With packagingExcludes, the tokens are completely excluded from the final war file.

With warSourceExcludes, the tokens are just ignored when copying the war directory into the war file.

As a result, if the tokens are present in the webappDirectory for example, they will not be ignored when using warSourceExcludes but will be when usingpackagingExcludes.

OTHER TIPS

The process of producing the final war file can be simplified as two major steps:

  1. the web resources are copied from ${warSourceDirectory} into ${<webappDirectory>}, let's say it's target/artifact/, which can be treated like:

    cp -r src/main/webapp/* target/artifact/
    

    <warSourceExcludes> is used at this step, so that the excluded files are NOT copied into target/artifact/.

  2. the output directory target/artifact of the above step, namely ${webappDirectory}, is then used as the input to produce the final war file, like:

    jar --create --file target/artifact.war -C target/artifact/ WEB-INF ...
    

    And here <packagingExcludes> is used, deciding what to pack up from target/artifact/.

see https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top