0

I have a Java web project that consumes a web service, using Apache CXF to generate the underlying code, based on the WSDL published by the service.

I have a test version of the service for development and a production version. The endpoints of the 2 services are at different URLs and whilst their public interfaces are pretty much identical I regenerate the CXF code (using the cxf-codegen-plugin) as I promote my project to the production environment.

What is the best way to configure Maven to do this?

At the moment I set a property in the pom.xml called ws_status

<properties>
    <ws_status>test</ws_status>
</properties>

which I subsequently use to tweak the path to the WSDL file used by the codegen plugin:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <configuration>
    <fork>once</fork>
    <encoding>UTF-8</encoding>
    <additionalJvmArgs>-Djava.endorsed.dirs=${project.build.directory}/endorsed</additionalJvmArgs>
    <!-- rest of the normal codegen configuration options -->
    </configuration>
    <dependencies>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-xjc</artifactId>
        <version>2.2</version>
    </dependency>
    </dependencies>
    <executions>
    <execution>
        <id>generate-sources</id>
        <phase>generate-sources</phase>
        <goals>
        <goal>wsdl2java</goal>
        </goals>
        <configuration>
        <wsdlOptions>
            <wsdlOption>
            <wsdl>${basedir}/src/main/resources/wsdl/${ws_status}/Cmis.wsdl</wsdl>
            <wsdlLocation>classpath:wsdl/${ws_status}/Cmis.wsdl</wsdlLocation>
            <extraargs>
                <extraarg>-client</extraarg>
                <extraarg>-verbose</extraarg>
                <extraarg>-compile</extraarg>
            </extraargs>
            </wsdlOption>
        </wsdlOptions>
        </configuration>
    </execution>
    </executions>
</plugin>

This works OK, but it annoys me that I need to change the ws_status inside the pom.xml every time I release a production version, as the pom file is tracked by git.

What I want is a maven command-line switch to tell it to refer to one WSDL file or the other , so I can generate the sources for the test or production environment without having to change the code inside the project. Is this the "build profile" in Maven speak?

Any ideas? Thanks.

Geeb
  • 631
  • 8
  • 19

1 Answers1

0

You should remove your property on the top of your POM. The you can call your Maven command lines as follows:

mvn goal -Dws_status=your_status_value

And it should be Ok.

YMomb
  • 2,366
  • 1
  • 27
  • 36
  • Thanks, good tip! This would have the desired effect. But ... I was actually looking for an example of using Maven's build profiles to achieve this. – Geeb Mar 14 '13 at 10:52
  • The problem is that to activate your profile you will have to call your command line with "-P profileName" which is similar to use -Dproperty=value. – YMomb Mar 14 '13 at 11:10
  • Absolutely. But I was thinking that if there were any other differences between test and production it would be useful to implement different build profiles to account for this, and to see an example. In this case, with a single property changing, your provided solution would suffice. – Geeb Mar 14 '13 at 11:23
  • I think what I really want is to get my head around the concept of Maven's "build profiles", but I find the documentation confusing. I was fishing for an example, really. Maybe I should go and RTFM! – Geeb Mar 14 '13 at 12:40