Reputation: 9612
I'm trying to call an external SOAP service within my Java application. To do this I want to generate the request and response objects from the wsdl exposed on some domain. I'm using the maven-jaxb2-plugin to do this:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>example.wsdl</generatePackage>
<schemas>
<schema>
<url>http://someaddress/example.wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
The thing is: I want to be able to able to change the URL of the WSDL (http://someaddress/example.wsdl) depending on what environment the application is going to be deployed to. I was thinking of using System properties to do this but is there some better practice to achieve this?
EDIT: After more searching I have found a similar questions but in a C# context. Might this help with coming up with a solution? How can you use two WSDLs and maintain a test instance with a C# application?
Upvotes: 0
Views: 1244
Reputation: 3002
Use Maven profiles
The example of configuration below:
<!-- Profile configuration -->
<profiles>
<!-- The configuration of the development profile -->
<profile>
<id>dev</id>
<!-- The development profile is active by default -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.url>http://someaddress/example.wsdl</build.profile.url>
</properties>
</profile>
<!-- The configuration of the production profile -->
<profile>
<id>prod</id>
<properties>
<build.profile.url>http://someaddress/example2.wsdl</build.profile.url>
</properties>
</profile>
<!-- The configuration of the testing profile -->
<profile>
<id>test</id>
<properties>
<build.profile.url>http://someaddress/example3.wsdl</build.profile.url>
</properties>
</profile>
</profiles>
and then in your plugin
<schemas>
<schema>
<url>${build.profile.url}</url>
</schema>
</schemas>
To install artifact with profile dev
use
mvn clean install -P dev
Upvotes: 2