maven - On build Exclude specific folders from being packaged on a WAR file

27 July 2014


How to avoid packaging unwanted folders on a java WAR file

You must use the maven-war plugin to enable this feature:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent> <artifactId>testAppWebParent</artifactId> <groupId>io.guilhebl.test</groupId> <version>1.0.0</version> <relativePath>../testAppWebParent/pom.xml</relativePath> </parent>

<artifactId>testApp</artifactId> <packaging>war</packaging> <name>Test Application</name>

<span class="nt">&lt;properties&gt;</span>
    <span class="nt">&lt;endorsed.dir&gt;</span>${project.build.directory}/endorsed<span class="nt">&lt;/endorsed.dir&gt;</span>
    <span class="nt">&lt;org.apache.maven.plugins.maven-war-plugin.version&gt;</span>2.3<span class="nt">&lt;/org.apache.maven.plugins.maven-war-plugin.version&gt;</span>
<span class="nt">&lt;/properties&gt;</span>

<span class="nt">&lt;dependencies&gt;</span>
<span class="nt">&lt;/dependencies&gt;</span>


<span class="nt">&lt;build&gt;</span>
    <span class="nt">&lt;plugins&gt;</span>
        <span class="nt">&lt;plugin&gt;</span>
            <span class="nt">&lt;groupId&gt;</span>org.apache.maven.plugins<span class="nt">&lt;/groupId&gt;</span>
            <span class="nt">&lt;artifactId&gt;</span>maven-war-plugin<span class="nt">&lt;/artifactId&gt;</span>
            <span class="nt">&lt;version&gt;</span>${org.apache.maven.plugins.maven-war-plugin.version}<span class="nt">&lt;/version&gt;</span>
            <span class="nt">&lt;configuration&gt;</span>
              <span class="nt">&lt;warSourceExcludes&gt;</span>test/**,scripts/**,node_modules/**,bower_components/**<span class="nt">&lt;/warSourceExcludes&gt;</span>
            <span class="nt">&lt;/configuration&gt;</span>
        <span class="nt">&lt;/plugin&gt;</span>
    <span class="nt">&lt;/plugins&gt;</span>
<span class="nt">&lt;/build&gt;</span>

</project>


The resulting WAR file will not have the above folders packaged as a result of the build, resulting in a smaller, more compact WAR file.

comments powered by Disqus