9

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?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
woky
  • 4,686
  • 9
  • 36
  • 44

3 Answers3

18

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>
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • Works like a charm. Thank you. Is it somehow possible to completely exclude it from build? I mean also from build directory (eg. target/myapp-1.0-SNAPSHOT). If not I guess I can live with copying wars. – woky Mar 08 '11 at 18:39
  • @woky. Updated answer in response to the additional query – Raghuram Mar 09 '11 at 03:38
  • @Raghuram: Unfortunately it doesn't work. (My Maven version: Apache Maven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)). – woky Mar 09 '11 at 12:36
  • 1
    @Nishant: Sure. I originally wanted to completely exclude it form build. That's why I haven't clicked "Answered" yet. – woky Mar 09 '11 at 12:42
  • Hi,i tried excluding files while building.But its not working.Any advise PLZ – user170114 Apr 27 '11 at 12:32
  • @user170114. You should ask a new question specifying details of your problem and not use this thread. This will help people see it and answer it. – Raghuram Apr 28 '11 at 08:35
  • 2
    Works to keep it out of the war, but it still ends up in the target directory. – SimplGy Feb 09 '12 at 15:11
3

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

pimlottc
  • 3,066
  • 2
  • 29
  • 24
0

Recently I had a similar problem with persistence.xml. Try putting this into your POM:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <excludes>
          <exclude>META-INF/context.xml</exclude>
        </excludes>
      </configuration>
    </plugin>
  </plugins>
</build>

If it does not help, try replace maven-jar-plugin with maven-war-plugin.

voho
  • 2,805
  • 1
  • 21
  • 26