Maven 2 如何在编译时将属性文件与Hudson一起使用?
我有一个pom.xml,它使用cxf codegen插件来生成几个WS客户端 在cxf codegen插件的配置中,有WSDL位置 我想将这些字符串外部化为env.properties文件 我使用org.codehaus.mojo的properties maven插件查看src/main/resources/conf/app/env.properties内部 我怎样才能让哈德逊用阿片剂主体替换这些属性Maven 2 如何在编译时将属性文件与Hudson一起使用?,maven-2,properties,hudson,environment,Maven 2,Properties,Hudson,Environment,我有一个pom.xml,它使用cxf codegen插件来生成几个WS客户端 在cxf codegen插件的配置中,有WSDL位置 我想将这些字符串外部化为env.properties文件 我使用org.codehaus.mojo的properties maven插件查看src/main/resources/conf/app/env.properties内部 我怎样才能让哈德逊用阿片剂主体替换这些属性 提前感谢如果我理解正确,您只想提供正确WSDL文件的路径。请参见中的以下示例 您可以阅读的路径
提前感谢如果我理解正确,您只想提供正确WSDL文件的路径。请参见中的以下示例 您可以阅读的路径,如您所述,使用。问题是加载正确的属性文件。这可以使用配置文件来完成
<profiles>
<profile>
<id>fitnesse</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-properties-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profiles>
合身
org.codehaus.mojo
,更改xml文件的语法可在过滤和配置文件中找到
设置husdon筛选器文件并放置在src/main/filters中。为需要运行的每个区域创建一个附加过滤器文件
过滤器文件的名称应类似,如:filter-hudson.properties、filter-prod.properties等,并包含相同的属性:
wsdl.host=myHost
etc...
然后创建包含运行环境的简单配置文件:
<profiles>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>hudson</id>
<properties>
<env>hudson</env>
</properties>
</profile>
</profiles>
戳
戳
哈德逊
哈德逊
如果随后在pom中设置过滤器:
<filters>
<filter>src/main/filters/filter-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources/conf/app</directory>
<filtering>true</filtering>
</resource>
</resources>
src/main/filters/filter-${env}.properties
src/main/resources/conf/app
真的
然后,conf应用程序中的文件将用过滤器中的特定值替换wsdl.host
然后在运行hudson构建时,添加-p hudson以调用hudson概要文件
也许有一种“更好”的方法可以做到这一点,但大约一年半前,我成功地使用了这种技术。为了给予适当的信任,以下是我用作说明的信息。是的,你误解了我的需要。基本上和你说的差不多,但有点不同。使用您的示例,假设属性${project.build.directory}是${wsdl.host},并且您希望从属性文件中读取它。我已经用属性maven插件做过了。好的,现在我只需要知道如何让Hudson在运行initialize的目标之前,用正确的值替换该属性值。作为澄清。所有内容(属性文件、wsdl)都已设置并正常工作?现在您只想修改属性文件,不是吗?如果是这种情况,请提供您打算使用的操作系统(限制选择)?如果属性文件中的所有参数都需要更改或不需要更改,这也会很有趣。
<profiles>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>hudson</id>
<properties>
<env>hudson</env>
</properties>
</profile>
</profiles>
<filters>
<filter>src/main/filters/filter-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources/conf/app</directory>
<filtering>true</filtering>
</resource>
</resources>