Generate Java class files from WSDL file using JAX-WS Maven Plugin

We use the WSDL file set to define API specs for SOAP Web Service. To easily and conveniently implement SOAP Web Service defined from the WSDL file, you can use the JAX-WS Maven Plugin to generate the necessary Java class files. How is it in detail? Let’s find out together in this tutorial!

First, I will create a new Maven project:

as an example.

I will define a WSDL file located in the project’s src/main/resources/wsdl directory with simple content as follows:

To use the JAX-WS Maven Plugin, we will declare it in the pom.xml file as follows:

There are many goals defined in JAX-WS Maven Plugin such as wsimport, wsgen, … but to generate Java class files, please use wsimport goal!

You can define to use wsimport goal as follows:

With this definition, wsimport goal will be executed when we run the “mvn install” command!

To configure the hello.wsdl file that I created above to generate Java class files, the package name and folder will contain these Java class files, you can use the <configuration> tag as follows:

We use the <wsdlFiles> tag along with the list of <wsdlFile> tags to configure the path to the WSDL files we want to generate! If you want to generate all WSDL files in a directory, you can use the <wsdlDirectory> tag instead of the <wsdlFiles> tag, for example:

Sometimes we will use a WSDL file from a link on the internet. In this case, you can use the <wsdlUrls> tag along with the list of <wsdlUrl> tags to configure the URL pointing to that path!

We configure the package name using the <packageName> tag and the directory containing the generated files using the <sourceDestDir> tag.

Now, if I run the command “mvn clean install” for my example project, you will see the following result:

JAX-WS Maven Plugin has generated the necessary files so we can implement SOAP Web Service!

Add Comment