I have succeeded in the same process. The aim is to create a web service proxy JAR for the web services in our application.
Web services
We have three web services in our application (currently). They are created by a Maven project that builds a WAR with the service and supporting classes, that contains a sun-jaxws.xml
descriptor as well as web.xml
.
The web-service Maven project is part of a multi-project build so the web-service WAR is one module in an EAR that also has an EJB JAR, user-interface WAR and other JARs (as well as dependencies).
Client proxy JAR
Ideally, I would create the client proxy JAR in another Maven project that depends on the web service WAR project and uses the Maven JAX-WS plugin goals wsgen
followed by wsimport
to do the work.
But I could not get a Maven project to use a WAR as a depedency so that its classes (in WEB-INF/classes
) are added to the class path. I tried the AppFuse Warpath plugin but could not get it to unpack the WAR dependency.
Two artifacts from one Maven project
In the end I had to resort to building and installing multiple artifacts in one Maven project. My findings about wsgen
and wsimport
and the second artifact:
jaxws-maven-plugin
needs its own dependencies for the wsgen
goal if they are outside the current project, otherwise it can’t find them. (Even if verbose
is set true
this goal emits little helpful information.)
- The
wsgen
goal must be called for each service to generate a WSDL.
- The
wsimport
goal is called once for on all WSDLs at once because the services share a number of support classes. (Because all generated classes go into one client proxy package, it is important to have no overlap of class names across the original sources, even if they originate in different packages.)
maven-jar-plugin:jar
and maven-install-plugin:install-file
are called to package and install the client proxy JAR.
Below are key parts of the POM with some comments:
<parent>
<groupId>lighthouse.navigate</groupId>
<artifactId>navigate</artifactId>
<version>3.9.0-SNAPSHOT</version>
</parent>
<artifactId>navigate-webservice</artifactId>
<packaging>war</packaging>
<name>Navigate WebService</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>navigate-util</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<!-- snip -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- WSDLs must be generated for each service. -->
<execution>
<id>generate-client-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei>nav.ws.client.ClientWebService</sei>
<genWsdl>true</genWsdl>
</configuration>
</execution>
<execution>
<id>generate-licence-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei>nav.ws.licence.LicenceWebService</sei>
<genWsdl>true</genWsdl>
</configuration>
</execution>
<!-- snip -->
<!-- Single generation of client proxy because WSDLs share classes. -->
<execution>
<id>generate-proxies</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>target/generated-sources/wsdl</wsdlDirectory>
<destDir>target/wsgen/classes</destDir>
<packageName>nav.ws.proxy</packageName>
<xnocompile>false</xnocompile>
</configuration>
</execution>
</executions>
<!--
NB: wsgen needs its own dependencies declared so it can find
classes outside this project.
-->
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>navigate-util</artifactId>
<version>${project.version}</version>
</dependency>
<!-- snip -->
</dependencies>
</plugin>
<!-- Package client proxy JAR as secondary artifact. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>package-wsclient</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target/wsgen/classes</classesDirectory>
<finalName>navigate-wsclient-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<!-- Install client proxy JAR as secondary artifact. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>install-wsclient</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>target/navigate-wsclient-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>navigate-wsclient</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>