2

Currently, I want to exclude some files from the default src/main/resources folder into my WAR when packaging

I tried using maven-war-plugin with the following configuration but failed.

<webResources>
  <resource>
    <directory>src/main/resources</directory>
    <targetPath>WEB-INF/classes</targetPath>
    <excludes>
      <exclude>*.xml</exclude>
    </excludes>
  </resource>
</webResources>

...WEB-INF/classes will still contain the XML files.

How to do so?

edrabc
  • 1,259
  • 1
  • 14
  • 23
user509392
  • 21
  • 1
  • 2
  • Just move them into an other location than src/main/resources – khmarbaise Nov 16 '10 at 10:54
  • This might be what you're looking for: http://stackoverflow.com/questions/3750189/maven2-excluding-directory-from-war –  Apr 13 '11 at 11:54

3 Answers3

5

As pointed out in https://stackoverflow.com/a/2737635/722997, a quick way to exclude files from the WAR package is to exclude them in the build->resources section, like:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>*.xml</exclude>
            </excludes>
        </resource>
    </resources>
    ...
</build>

Note: take into account that the following configuration will only affect default executions of Maven (WAR package, JAR package, ...), but not assemblies or other user configurations.

Community
  • 1
  • 1
edrabc
  • 1,259
  • 1
  • 14
  • 23
1

This is somewhat late to this question, but I was just trying to do the same thing, and have found that (with the maven-war-plugin 3.1.0 version), adding:

<packagingExcludes>WEB-INF/classes/*.xml</packagingExcludes>

to the configuration should do what was asked for (it worked for me to remove properties files we didn't want to distribute with the war file).

Matt Harrison
  • 338
  • 3
  • 10
0

From the documentation of maven war plugin, you can include and exclude resources as follows:

...
        <configuration>
          <webResources>
            <resource>
              <!-- the default value is ** -->
              <includes>
                <include>**/pattern1</include>
                <include>*pattern2</include>
              <includes>
              <!-- there's no default value for this -->
              <excludes>
                <exclude>*pattern3/pattern3</exclude>
                <exclude>pattern4/pattern4</exclude>
              </excludes>
            </resource>
          </webResources>
        </configuration>
        ...

Are you following this and it still does not work? If so, can you post your pom snippet?

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • 1. If using the following: **/log4j.xml ${basedir}/src/main/webapp . **/osirisws-servlet.xml **/osirisws-servlet.xml,**/log4j.xml – user509392 Nov 17 '10 at 03:45
  • got exception: [INFO] Trace java.lang.NullPointerException at org.apache.maven.plugin.war.AbstractWarMojo.copyResources(AbstractWarMojo.java:395) at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:325) at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:167) at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:133) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:483) at – user509392 Nov 17 '10 at 03:49
  • 2. If using the following ${basedir}/src/main/resourcesWEB-INF/classes **/log4j.xml ${basedir}/src/main/webapp . **/osirisws-servlet.xml **/osirisws-servlet.xml,**/log4j.xml – user509392 Nov 17 '10 at 03:53
  • log4.xml still existing in WEB-INF\classes so, can't be excluded while osirisws-servlet can be excluded. – user509392 Nov 17 '10 at 03:54