How to exclude files from being copied, by maven, into the exploded war
Solution 1
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).
Solution 2
I could find no configuration of <warSourceExcludes> which worked, however <packagingExcludes> did work:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<packagingExcludes>excludeMe/**</packagingExcludes>
</configuration>
</plugin>
Solution 3
Your warSourceExcludes is wrong. Here is what the maven-war-plugin says regarding warSourceExludes:
The comma separated list of tokens to exclude when copying the content of the warSourceDirectory.
So in your case this is what your configuration should look like:
<configuration>
...
<warSourceExcludes>client/</warSourceExcludes>
...
</configuration>
This means also that if you want to add some more excludes, just add them separated with a comma:
<configuration>
...
<warSourceExcludes>client/,otherDir/,evenMoreDir/</warSourceExcludes>
...
</configuration>
Solution 4
In order to exclude all files from folder use wildcards like that client/**
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<overlays>
</overlays>
<webappDirectory>${project.build.directory}/${project.build.finalName}-work</webappDirectory>
<warSourceExcludes>client/**</warSourceExcludes>
</configuration>
Kris
Updated on July 13, 2022Comments
-
Kris about 1 yearI 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 (explodedorpackaged).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
warSourceExcludesto exclude certain paths, but to no avail. An example of my usage is shown below, whereclient/is a folder directly beneathsrc/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?
UPDATE
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? -
Kris over 10 yearsHi,First off thanks for the response. just tried your suggestion with no luck, Will update my question to include what I have tried. thanks -
maba over 10 yearsI tried with your setup and I got a folder intargetthat ends with-workand in that folder there is no sign of theclientdirectory. -
maba over 10 yearsDo you want to create a war as well with the same layout? Or is the exploded war the only result you want? -
Kris over 10 yearsstrange.... I am runningmvn clean war:explodedand theclient/still gets copied over. Not sure what is going on here -
Kris over 10 yearsforgot to say I want it excluded from the packaged war as well -
maba over 10 yearsThat's how maven plugins work. They have either configuration bound to be executed in a build OR configuration for command line execution. Take a look at themaven-dependency-pluginas an example. It is quite specific about how the two configuration parts differ. Your requirements were not totally clear. But it's nice that you now have a working configuration. -
Kris over 10 yearsthanks for the clarification - and apollogies if I didn't describe the issue correctly (probably due to me not really getting the finer details of maven). But thanks again maba @aleksandr for your help! -
maba over 10 yearsIf you found our answers useful/helpful then upvote them. And accept your own answer if that is what you found to be the best solution. -
Kris over 10 yearsyes, apologies. Have up-voted your answers as they were indeed useful. thanks again -
Cesar about 8 yearsThat solved my problem with minify-maven-plugin, which was keeping the concatenated files in my .war, even with the use of <warSourceExcludes>. -
jediz over 6 yearsnote thatpackagingExcludesonly excludes from the.warfile, not from the exploded folder -
lenach87 about 3 yearsgreat you mentioned that part on execution section, saved me now 8 years later from the same mistake.