0

我有一个使用 cxf-codegen-plugin 生成几个 WS 客户端的 pom.xml。

在 cxf-codegen-plugin 的配置中,有 WSDL 位置。

我想将这些字符串外部化到 env.properties 文件中。

我使用 org.codehaus.mojo 的 properties-maven-plugin 来查看 src/main/resources/conf/app/env.properties。

我怎样才能让 Hudson 用合适的主机替换这些属性?

提前致谢

4

2 回答 2

2

过滤和配置文件应该可以工作。

设置一个 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>

然后 conf app 中的文件将 wsdl.host 替换为过滤器中的特定值。

然后,当您运行 hudson 构建时,添加 -P hudson 以调用 hudson 配置文件。

可能有一种“更好”的方法可以做到这一点,但大约一年半前,我用这种技术取得了成功。为了给予适当的信任,这是我用作说明的博客文章。

于 2010-12-28T14:46:39.450 回答
0

如果我理解正确,您只想提供正确 WSDL 文件的路径请参阅cxf-codgen 插件中的以下示例。

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

此处 WSDL 的路径仅由basedir修改,您可以将该行修改为:

...
<wsdl>${basedir}/${myRelativePath}/myService.wsdl</wsdl>
...

正如您所提到的,您可以使用properties-maven-plugin读取的路径。问题是加载正确的属性文件。这可以使用配置文件来完成。

<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>

如果所有属性只影响 wsdl 文件,那么您可以在配置文件中配置正确 wsdl 文件的路径,这样就不需要属性文件了。


以防万一,我完全误解了你,你只想知道,如何从属性文件中读取属性到 wsdl (xml) 文件中,然后看看maven-config-processor-plugin,语法用于更改 xml 文件的内容可在转换配置页面上找到

于 2010-12-27T14:50:50.400 回答