Using wsimport
on the command prompt allows you to generate a client jar
, .java
, and or .class
files depending on the options you pass to it. To use it in Maven
, you need to following stuff in your pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <!-- there will be strange javadocs generated from the xsds, as we are not havily depending on them just ignore them for now --> <failOnError>false</failOnError> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.9</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/target/generated/src/main/java</source> </sources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>1.12</version> <configuration> <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory> <packageName>com.turreta.wsclient.ws001</packageName> <keep>true</keep> <sourceDestDir>${basedir}/target/generated/src/main/java</sourceDestDir> </configuration> <executions> <execution> <goals> <goal>wsimport</goal> </goals> </execution> </executions> </plugin> </plugins> </build> |
There are things worth noting.
Target path of generated java file
This is for build-helper-maven-plugin
and is referred to the location where the artifacts are created from the WSDL
file.
1 2 3 4 5 6 7 8 | ... <configuration> <sources> <source>${basedir}/target/generated/src/main/java</source> </sources> </configuration> ... |
Config for jaxws-maven-plugin
Now this is for jaxws-maven-plugin
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>1.12</version> <configuration> <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory> <packageName>com.turreta.wsclient.ws001</packageName> <keep>true</keep> <sourceDestDir>${basedir}/target/generated/src/main/java</sourceDestDir> </configuration> <executions> <execution> <goals> <goal>wsimport</goal> </goals> </execution> </executions> </plugin> ... |
Since we are using a WSDL file, we need to define the <wsdlDirectory> option to refer to the path where the WSDLs are. The <packageName>
is a way to organize the generated codes into their own package. <sourceDestDir>
is similar to the one we defined for build-helper-maven-plugin
.
To build the maven project, use the wsimport
goal.
For instance,
1 | mvn wsimport |