从Maven构建中排除文件

编程入门 行业动态 更新时间:2024-10-26 00:23:24
本文介绍了从Maven构建中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

本文发布于:2023-11-16 16:57:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!