Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude file from maven build

Tags:

maven

I've a web application with file src/main/webapp/META-INF/context.xml which contains some configuration for testing database. On production server this file is in $TOMCAT_HOME/conf/Catalina/localhost/ROOT.xml and I'm testing with embedded tomcat so I don't want to package this file. I'd like to exclude this file from maven build. I tried following:

<build>
  ...
  <resources>
    <resource>
      <directory>src/main/webapp/META-INF</directory>
      <filtering>true</filtering>
      <excludes>
        <exclude>context.xml</exclude>
      </excludes>
    </resource>
  </resources>
</build>

and also following:

<build>
  ...
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <resources>
        <resource>
          <directory>src/main/webapp/META-INF</directory>
          <filtering>true</filtering>
          <excludes>
            <exclude>context.xml</exclude>
          </excludes>
        </resource>
      </resources>
    </configuration>
  </plugin>
</build>

But the file still gets packaged in war and in build directory (eg. target/myapp-1.0-SNAPSHOT/META-INF/context.xml). What am I doing wrong?

like image 857
woky Avatar asked Mar 07 '11 16:03

woky


2 Answers

You can try using the packagingExcludes parameter

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <packagingExcludes>META-INF/context.xml</packagingExcludes>
    </configuration>
</plugin>

To exclude a resource from build, the first snippet in the question looks fine, except that the absolute path of the resource directory should be specified. For instance

<directory>${basedir}/src/main/webapp/META-INF</directory>
like image 104
Raghuram Avatar answered Nov 16 '22 01:11

Raghuram


The others have answered the main question but one other detail I noticed from your original attempted solution -

      <filtering>true</filtering>

In Maven, "resource filtering" doesn't mean what you probably think it means. It's not about including/excluding resources but rather whether they should be processed to fill in embedded variable references.

See http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

like image 21
pimlottc Avatar answered Nov 16 '22 02:11

pimlottc