I have a Java web app, in which I have some folders within the standard webapp source directory (src/main/webapp)
that I don't want to get copied over into the war (exploded
or packaged
).
One of the reasons I don't want these files copying over is that we run the YUI JS & CSS minimizer & compressor on .js and .css files within the exploded war. The files that I want to exclude produce errors during the compression phase. The other reason I don't want them adding to the war is that they support testing a single page JS app that lives within the webapp (they are client side JS test scripts that rely on node
/ angular.js
).
Below are the relevant sections from the POM.xml
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>parent-resources</id>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<overlays>
</overlays>
<webappDirectory>${project.build.directory}/${project.build.finalName}-work</webappDirectory>
</configuration>
<phase>generate-sources</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
I have tried, unsuccessfully, to use warSourceExcludes
to exclude certain paths, but to no avail. An example of my usage is shown below, where client/
is a folder directly beneath src/main/webapp
:
<configuration>
...
<warSourceExcludes>
<excludes>
<exclude>
client/
</exclude>
</excludes>
</warSourceExcludes>
...
</configuration>
What is the correct way to exclude certain paths, and or individual files, within the web app source directory from being included in the exploded war?
Following on from the suggestion from @maba I updated the configuration as follows:
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<overlays>
</overlays>
<webappDirectory>${project.build.directory}/${project.build.finalName}-work</webappDirectory>
<warSourceExcludes>client/</warSourceExcludes>
</configuration>
The folder, client/
, still is getting copied across. Any ideas?
Thanks to @alexksandr & @maba for their answers - which though correct didn't fully resolve my issue.
The solution seems to be - though I am not sure exactly why this is the case - that the configuration section is not picked up on when it is placed within the execution
section.
Taking my original pom.xml and re-factoring it to make it work gives:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<overlays>
</overlays>
<webappDirectory>${project.build.directory}/${project.build.finalName}-work</webappDirectory>
<warSourceExcludes>client/</warSourceExcludes>
</configuration>
<executions>
<execution>
<id>parent-resources</id>
<phase>generate-sources</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
The important detail seems to be that the configuration should be at the top level of the plugin and not within the execution
section - though clearly the xml
in my first attempt to use warSourceExcludes
was way off target (see original question prior to the update section).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With