如何根据目标环境在Maven中复制资源或其他资源? [英] How to copy a resource or another in Maven depending on the target environment?
问题描述
我必须创建测试战争和生产战争,这将在WEB-INF
目录中具有不同的log4j.properties
文件.我有这些文件log4j.properties
(测试战争)和dev.log4j.properties
(用于生产娱乐).
I have to create test war and production war, which will have a different log4j.properties
file in the WEB-INF
directory. I have these files log4j.properties
(test war) and dev.log4j.properties
(for production enivorment).
如何将dev.log4j.properties
文件复制到log4j.properties
文件中以进行生产战争?
How to copy the dev.log4j.properties
file into log4j.properties
file for production war?
推荐答案
- 使用Maven配置文件( http://maven.apache.org/guides/introduction/introduction-to-profiles.html )
-
创建一个"dev"和"prod"配置文件,为每个配置文件选择一组备用资源.默认情况下,使开发人员处于活动状态.
- Use Maven profiles (http://maven.apache.org/guides/introduction/introduction-to-profiles.html)
Create a "dev" and "prod" profile, selecting an alternate set of resources for each profile. Make Dev active by default.
<profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <resources> <resource> <directory>src/main/resources/dev</directory> </resource> </resources> </build> </profile> <profile> <id>prod</id> <build> <resources> <resource> <directory>src/main/resources/prod</directory> </resource> </resources> </build> </profile> </profiles>
-
使用所需的配置文件通过以下方式进行构建:
mvn install -Pdev
或者mvn install -Pprod
Build using the desired profile via:
mvn install -Pdev
ormvn install -Pprod
这篇关于如何根据目标环境在Maven中复制资源或其他资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!