从Maven构建中排除文件 [英] exclude file from maven build
问题描述
我有一个Web应用程序,文件为src/main/webapp/META-INF/context.xml,其中包含一些用于测试数据库的配置.在生产服务器上,此文件位于$ TOMCAT_HOME/conf/Catalina/localhost/ROOT.xml中,并且我正在使用嵌入式tomcat进行测试,因此我不想打包该文件.我想从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>
以及以下内容:
<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>
但是该文件仍然打包在war和构建目录中(例如target/myapp-1.0-SNAPSHOT/META-INF/context.xml).我在做什么错了?
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?
推荐答案
您可以尝试使用packagingExcludes
参数
<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>
要从构建中排除资源,问题中的第一个代码片段看起来不错,只是应指定resource
directory
的绝对路径.例如
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>
这篇关于从Maven构建中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!