Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

exclude file from maven build

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...