How is filtering done in the WAR plugin?

To enable filtering of web.xml you must configure the WAR Plugin like this:

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
          <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
        </configuration>
      </plugin>

Examples can be found here.

[top]


How does the classifier of dependency artifacts affect my WAR project?

When used, the copy of the dependency artifact in your project will have the classifier appended to its filename. This can be used to differentiate duplicate artifacts.

[top]


How do I exclude transitive dependencies from my project?

Give it a "provided" scope.

[top]


What's the difference between using dependentWarExclude and provided scope?

dependentWarExclude is used in overlays for excluding dependent WAR files from the assembled webapp.

[top]


How do I exclude files in my web resources?

Use the <webResources> / <exclude> parameter to identify the tokens to exclude.

For more information refer to Adding and Filtering External Web Resources.

[top]


How do I exclude files when doing overlays?

Use the dependentWarExcludes parameter to identify the tokens to exclude.

[top]


Where can I find the documentation for the plugin's configuration?

For each goal, you can use the documentation from the plugin site.

If you need a specific version, generate it using mvn site:site or use:

mvn help:describe -Dplugin=war -Dfull=true -Dversion=<your-plugin-version-here>

[top]


How do I create a JAR containing the classes in my webapp?

If you would simply like to package the classes and resources as a JAR in WEB-INF/lib rather than as loose files under WEB-INF/classes, use the following configuration:

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
          <archiveClasses>true</archiveClasses>
        </configuration>
      </plugin>

If you need to re-use this JAR in another project, the recommended approach is to move the classes to a separate module that builds a JAR, and then declare a dependency on that JAR from your webapp as well as from any other projects that need it.

If you can't move the classes to another project, you can deploy the classes and resources included in your webapp as an "attached" artifact, with a classifier, by using the following configuration:

<project>
  ...
  <artifactId>mywebapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
        <configuration>
          <attachClasses>true</attachClasses>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

This will result in two artifacts being deployed: mywebapp-1.0-SNAPSHOT.war and mywebapp-1.0-SNAPSHOT-classes.jar.

[top]