我有一个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构建中排除文件
发布评论