Etienne
Etienne

Reputation: 181

Maven: exclude resource from war

I am currently trying to exclude some resource from my built war. I have read the documentation and the forums, and found a lot of informations.

Unfortunately nothing worked in my case...

I have an Eclipse Maven project, and if I'm right, maven-war-plugin is the default "war builder", so I have to override it in my pom.xml in order to exclude the resource from the buildt war.

I tried warSourceExcludes, packagingExcludes and webResources/excludes :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven.war.version}</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <warSourceExcludes>src/main/webapp/frontEndWorkspace</warSourceExcludes>
        <packagingExcludes>src/main/webapp/frontEndWorkspace
        </packagingExcludes>
        <webResources>
            <resource>
                <!-- this is relative to the pom.xml directory -->
                <directory>src/main/webapp</directory>
                <!-- the list has a default value of ** -->
                <excludes>
                    <exclude>**/frontEndWorkspace</exclude>
                </excludes>
            </resource>
        </webResources>
    </configuration>
</plugin>

Despite this configuration, I still have the frontEndWorkspace directory pushed in my Tomcat...

I wonder if it comes from the fact that I use it in my Eclipse environment?

Thanks in advance!

Upvotes: 2

Views: 6215

Answers (2)

dam
dam

Reputation: 407

I am finding the same issue within Intellij IDEA which is using Maven 3.
The war file it generates contains the directory I am excluding.
UPD Solution is to use syntax as below to eliminate the myFolder directory

<webResources>
    <resource>
      <!-- this is relative to the pom.xml directory -->
      <directory>src/main/resources</directory>
         <excludes>
           <exclude>**/myFolder/**</exclude>
         </excludes>
    </resource>

</webResources>

Upvotes: 1

Fabien
Fabien

Reputation: 879

The parameters that you can use are packagingExcludes which is more generic (applies on the complete war structure) or warSourceExcludes if the files you want to exclude are specifically in the folder defined by the parameter warSourceDirectory (default being ${basedir}/src/main/webapp) (see here). It works easily when you know that it starts considering the folder structure of the war.

Example :

This will exclude all the files finishing by *.jsp contained in the folder WEB-INF of the folder defined by the parameter warSourceDirectory (default being ${basedir}/src/main/webapp) :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <warSourceExcludes>WEB-INF/**/*.jsp</warSourceExcludes>
    </configuration>
</plugin>

This will exclude all the files contained in all the folders pouet contained in the war (but not the folder structure) :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <packagingExcludes>**/pouet/**/*.*</packagingExcludes>
    </configuration>
</plugin>

The problem of your configuration <warSourceExcludes>src/main/webapp/frontEndWorkspace</warSourceExcludes> is that you start from the source folder which is wrong. You just have to remove src/main/webapp and add /** after frontEndWorkspace to have <warSourceExcludes>/frontEndWorkspace/**</warSourceExcludes> working (or <warSourceExcludes>frontEndWorkspace/**</warSourceExcludes>).

Upvotes: 4

Related Questions