如何创建一个Maven构建配置文件来有条件地复制文件? [英] How can I create a Maven build profile to conditionally copy files?
问题描述
我要新Maven和我想创建的pom.xml生成使用配置文件不同的环境战争文件
I new to maven and I am trying to create pom.xml to build the war files for different environment using profiles
因此,我创建的构建目标
So I created the build target
<build>
<finalName>myacct_okc</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>config/${environment}</directory>
</resource>
</resources>
</build>
然后创建的配置文件为每个环境
And then created the profiles for each environment
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<environment>local</environment>
</properties>
</profile>
<profile>
<id>jboss</id>
<properties>
<environment>jboss</environment>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<environment>dev</environment>
</properties>
</profile>
和我每个ENV创建一个配置文件夹
and I create a config folder for each env
project root
|-- src
| |-- main
| | |-- java
| | |-- resources
| | | |-- config.xml
| | | +-- config.properties
| | |-- webapp
| | | |-- META-INF
| | | | +--context.xml
| | |-- config
| | | |-- local
| | | | |--config.properties
| | | | +--config.xml
| | | |-- jboss
| | | | |--config.properties
| | | | +--config.xml
| | | +-- dev
| | | | |--config.properties
| | | | +--config.xml
+--pom.xml
现在,当我运行这个pom.xml中与例如任何配置文件JBoss的,文件形成的config / JBoss的文件夹都没有得到复制(或我的意思是没有得到替换的src / main /资源文件)。
Now when I run this pom.xml with any profile for e.g. jboss, the files form config/jboss folder are not getting copied ( or I mean the files in src/main/resources are not getting replaced).
当我启用了调试上Maven构建我可以看到得到执行的副本。
when I enabled the debug on on maven build I can see the copy getting executed.
[DEBUG] resource with targetPath null
directory C:\Projects\workspace\myaccount_build_4\myaccount\config\jboss
excludes []
includes []
[DEBUG] ignoreDelta true
[INFO] Copying 2 resources
[DEBUG] file config.xml has a filtered file extension
[DEBUG] copy C:\Projects\workspace\myaccount_build_4\myaccount\config\jboss\config.xml to C:\Projects\workspace\myaccount_build_4\myaccount\target\classes\config.xml
[DEBUG] file config.properties has a filtered file extension
[DEBUG] copy C:\Projects\workspace\myaccount_build_4\myaccount\config\jboss\META-INF\config.properties to C:\Projects\workspace\myaccount_build_4\myaccount\target\classes\META-INF\config.properties
但它不替换的文件。这些文件仍然是一样的,从钢骨混凝土/主/资源。
But it is not replacing the files. The files are still the same as from src/main/resources.
Maven的版本是3.0.4。
Maven version is 3.0.4
有人可以帮助我什么,我做错了什么?
Can someone help me what I am doing wrong ?
我已经看过这个<一个href=\"http://stackoverflow.com/questions/12729513/how-to-overwrite-files-in-the-war-file-during-maven-build\">question.这提供了一个解决方案,但我想覆盖文件,而不是排除它们,然后复制。
I have looked at this question. This provides a solution but I want to override the files rather then excluding them and then copy.
推荐答案
据我的工作后加入过滤=真
<build>
<finalName>myacct_okc</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>true</filtering>
<directory>config/${environment}</directory>
</resource>
</resources>
</build>
这篇关于如何创建一个Maven构建配置文件来有条件地复制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!