Rom*_*las 7 build-automation build-process maven-2
我正在使用Maven2来构建一个WAR项目.某些属性文件取决于发布的目标环境.
除了WAR之外,我想传递一个名为的文件datasource.xml
.此文件已存在于我的项目目录中,但包含将在构建期间过滤的属性(即某些${foo.bar}
).
换句话说,运行命令mvn clean install之后,我想在我的target/
目录中看到两个文件,my-webapp.war
和datasource.xml
.
请注意,工件中datasource.xml
不得包含my-webapp.war
!
我怎样才能做到这一点?
Ric*_*ler 10
您可以使用build-helper-maven-plugin附加其他工件.下面的配置会在封装阶段将datasource.xml附加为附加工件.如果该工件在src/main/resources和src/main/webapp之外定义,它将不会包含在战争中.
更新:为了确保对您的注释应用资源过滤,您可以指定资源插件的复制资源目标的执行,指定要应用的过滤.然后,您仍然可以使用build-helper-maven-plugin通过引用相应的目标目录来附加该过滤的工件.我已更新下面的示例以显示此用法.
<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>
Run Code Online (Sandbox Code Playgroud)
这不会出现在目标文件夹中,但会与战争一起部署/安装到存储库中.
可以通过使用分类器"datasource"定义依赖项来引用附加的工件.例如:
<dependency>
<groupId>my.group.id</groupId>
<artifactId>my-artifact-id/artifactId>
<version>1.0.0</version>
<classifier>datasource</classifier>
<type>xml</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
您可以使用依赖项插件的复制目标来检索工件,并将其作为部署过程的一部分放在需要的位置.
归档时间: |
|
查看次数: |
5186 次 |
最近记录: |