Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude files from being copied, by maven, into the exploded war

Tags:

maven

war

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?

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?

like image 322
Kris Avatar asked Nov 05 '12 10:11

Kris


1 Answers

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).

like image 64
Kris Avatar answered Sep 30 '22 20:09

Kris