开发者

How to use a properties file with Hudson in compilation time?

I have a pom.xml that uses cxf-codegen-plugin to generate a couple of WS clients.

Inside the configuration of cxf-codegen-plugin, there are the WSDL locations.

I would like to externalize those strings to a env.properties file.

I used org.codehaus.mojo's properties-maven-plugin to look inside src/main/resources/co开发者_C百科nf/app/env.properties.

How can I make Hudson to replace those properties with the apropiate host?

Thanks in advance


Filtering and profiles should work.

Setup a husdon filter file and place in src/main/filters. Create an additional filter file for each region you need to run in.

The filter files should be named similarly, like so: filter-hudson.properties, filter-prod.properties, etc. and contain the same properties:

wsdl.host=myHost
etc...

Then have simple profiles that contain the environment you run on:

<profiles>
  <profile>
    <id>prod</id>
    <properties>
      <env>prod</env>
    </properties>
  </profile>
  <profile>
    <id>hudson</id>
    <properties>
      <env>hudson</env>
    </properties>
  </profile>
</profiles>

If you then setup your filters in your 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>

Then the files in conf app will have wsdl.host replaced with the specific values in your filter.

Then when you run your hudson build, add -P hudson to invoke the hudson profile.

There may be a "better" way to do this, but about a year and a half ago, I had success with this technique. To give proper credit, here's the blog post I used as instructions.


If I understand you correctly, you just want to provide the path to correct WSDL file. See the following example from cxf-codgen plugin.

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

Here the path to the WSDL is modified only by the basedir, You can modify that line to:

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

The path you can read, as mentioned by you, using the properties-maven-plugin. The issue is to load the right properties file. This can be done using a profile.

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

If all properties only effect the wsdl file, than you can configure the path to the right wsdl file in the profile, which eliminates the need for the properties file.


Just in case, that I completely misunderstood you and you only wanted to know, how to get the properties read from the property file into the wsdl (xml) file, then have a look at the maven-config-processor-plugin, the syntax for changing xml files is found on the Transformation Configuration page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜