What is the difference between `warSourceExcludes` and `packagingExcludes` in Maven

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.


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

  1. the web resources are copied from ${warSourceDirectory} into ${<webappDirectory>}, which can be treated like:

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

    <warSourceExcludes> is used at this step, so that excluded files are not copied into the target dir.

  2. the content of the produced war file comes from ${webappDirectory}, namely the target/<artifact> directory, like:

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

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

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