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.