Maven – Exclude certain resource files into WAR from the default src/main/resources location

mavenwar

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?

Best Answer

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.

Related Topic