除工件外,如何交付属性文件? [英] How to deliver properties files in addition to artifacts?
问题描述
我正在使用 Maven2 来构建WAR项目. 某些属性文件取决于发行版的目标环境.
I am using Maven2 to build a WAR project. Some properties files are dependent on the environment targeted for a release.
除了WAR,我还想提供一个名为datasource.xml
的文件.该文件已经存在于我的项目目录中,但是包含在构建过程中将被过滤的属性(即某些${foo.bar}
).
I want to deliver, in addition of the WAR, a file called datasource.xml
. This file already exists in my project directory, but contains properties that will be filtered during the build (i.e. some ${foo.bar}
).
换句话说,在运行命令 mvn clean install 之后,我想在我的target/
目录中看到两个文件my-webapp.war
和datasource.xml
.
In others words, after running the command mvn clean install, I want to see in my target/
directory two files, my-webapp.war
and datasource.xml
.
请注意,my-webapp.war
工件中不得包含datasource.xml
!
Note that datasource.xml
must not be included in the my-webapp.war
artifact!
我该怎么做?
推荐答案
You can attach additional artifacts using the build-helper-maven-plugin. The configuration below would attach datasource.xml as an additional artifact during the package phase. If that artifact is defined outside of src/main/resources and src/main/webapp it will not be included in the war.
Update: to ensure resource filtering is applied per your comment, you can specify an execution of the resource-plugin's copy-resources goal, specifying filtering to be applied. You can then still attach that filtered artifact using the build-helper-maven-plugin by referencing the corresponding target directory. I've updated the example below to show this usage.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/datasource</outputDirectory>
<resources>
<resource>
<directory>src/main/datasource</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.outputDirectory}/datasource/datasource.xml</file>
<type>xml </type>
<classifier>datasource</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
它不会出现在目标文件夹中,但会在战争中部署/安装到存储库中.
This won't appear in the target folder, but it will be deployed/installed to the repository alongside the war.
可以通过使用分类器数据源"定义依赖项来引用附加的工件.例如:
The attached artifact can be referenced by defining a dependency with the classifier "datasource". For example:
<dependency>
<groupId>my.group.id</groupId>
<artifactId>my-artifact-id/artifactId>
<version>1.0.0</version>
<classifier>datasource</classifier>
<type>xml</type>
</dependency>
您可以使用依赖项插件的复制目标检索工件,并将其放在部署过程中所需的任何位置.
You could use the the dependency plugin's copy goal to retrieve the artifact and put it wherever it is required as part of your deployment process.
这篇关于除工件外,如何交付属性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!