How to parse WSDL using JAX-WS Maven plugin and generate java classes?
Java API for XML Web Services (JAX-WS) is a Java API for creating SOAP based web services, part of the Java EE platform. If you are using Maven as a build tool, you can use the JAX-WS Maven plugin to parse your WSDL file. In the maven pom.xml you have to mention all the details of this plugin under- Article by Kunal Chowdhury ontag. There could be two different approaches as detailed below.
In the previous blog post, we learnt how to parse WSDL using the 'wsimport' tool. That's not the only option to parse a WSDL file in Java. If you are using Maven as a build tool, you can perform the same using '
In this tutorial, we are going to learn how you can use the 'JAX-WS' Maven plugin to parse a WSDL file to generate java classes.
By setting the wsdlUrl tag
The first option is by setting the wsdlUrl tag of the plugin, which resides in the pom.xml file. To do this, open your pom.xml file and add the JAX-WS Maven plugin under the
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>2.4.1</version> <executions> <execution> <id>wsdltoJava</id> <goals> <goal>wsimport</goal> </goals> <configuration> <wsdlUrls> <wsdlUrl>[WSDL_URL]</wsdlUrl> </wsdlUrls> <vmArgs> <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> </vmArgs> <keep>true</keep> <packageName>[TARGET_NAMESPACE]</packageName> <sourceDestDir>[SOURCE_DIRECTORY]</sourceDestDir> </configuration> </execution> </executions> </plugin> </plugins> </build>
* Make sure to set the [WSDL_URL], [TARGET_NAMESPACE] and [SOURCE_DIRECTORY], as highlighted above.
By setting the wsdlFile tag
The another option to generate the java classes is by setting the wsdlFile tag of the plugin, which resides in the pom.xml file. If you have the .wsdl file saved locally, you can go with this option. To do this, open your pom.xml file and add the JAX-WS Maven plugin under the
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>2.4.1</version> <executions> <execution> <id>wsdltoJava</id> <goals> <goal>wsimport</goal> </goals> <configuration> <wsdlDirectory>[WSDL_FILE_PATH]</wsdlDirectory> <wsdlFiles> <wsdlFile>[WSDL_FILE_NAME]</wsdlFile> </wsdlFiles> <vmArgs> <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> </vmArgs> <keep>true</keep> <packageName>[PACKAGE_NAME]</packageName> <sourceDestDir>[SOURCE_DIRECTORY]</sourceDestDir> </configuration> </execution> </executions> </plugin> </plugins> </build>
* Make sure to set the [WSDL_FILE_PATH], [WSDL_FILE_NAME], [TARGET_NAMESPACE] and [SOURCE_DIRECTORY], as highlighted above.
Points to note that:
- The
- The
- The
- The