Wednesday, June 9, 2010

WSIMPORT configuration in Maven

While developing a webservice client, we need to generate the client stub from the wsdl. There are many ways of doing this. One way is to use the Maven wsimport plugin.

Below is the way how we do it.

Use "mvn -P wsimport" generate a fresh JAX-WS client, then check that client
into subversion as source. Whenever the service contract changes, run mvn wsimport again. (Each time you
run it with the wsimport profile, maven will clean the source folder and regenerate all the JAX-WS client Javas)

Use the following link to learn how to make a Spring config for Spring-loading the JAX-WS client:
http://static.springsource.org/spring/docs/2.5.x/reference/remoting.html#remoting-web-services-jaxws-access

Note: if you don't specify the wsimport profile with the "mvn -P wsimport" command, then this module simply builds
a straight java jar. This nice selective build feature of maven lets us checkin the jaxws java artifacts to
subversion, and lets us control when we do new java generation only when the service interface changes.


<profiles>
<profile>
<id>wsimport</id>
<build>
<defaultGoal>install</defaultGoal>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-3</version>
<configuration>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
<archiverConfig>
<duplicateBehavior>
skip
</duplicateBehavior>
</archiverConfig>
</configuration>
</plugin>

<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>
src/main/java/com/company/proj/serviceclient/module
</directory>
<includes>
<include>
**/*.java
</include>
<include>
**/*.properties
</include>
</includes>
<followSymlinks>
false
</followSymlinks>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>

<execution>
<id>UserManagementClient</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<keep>true</keep>
<sourceDestDir>src/main/java</sourceDestDir>
<xdebug>true</xdebug>
<verbose>true</verbose>
<target>2.1</target>
<extension>true</extension>
<bindingFiles><bindingFile>${basedir}/src/main/resources/generateElementProperty.binding</bindingFile></bindingFiles>
<!-- <xauthFile>${basedir}/src/main/resources/authFile</xauthFile> -->
<wsdlUrls>
<wsdlUrl>
http://server.companyname.com:8001/projectcontext/1.0.0?wsdl
</wsdlUrl>
</wsdlUrls>
<packageName>
com.equinix.gse.serviceclient.usermanagement
</packageName>
</configuration>
</execution>
</executions>


<!-- if you want to use a specific version of JAX-WS, you can do so like this -->
<!--dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies-->
</plugin>

</plugins>

</build>
</profile>
</profiles>

No comments:

Post a Comment