How to parse a WSDL file using 'wsimport' tool and generate java classes?


The Web Services Description Language (WSDL) is an XML based interface definition language that is used for describing the functionality offered by a SOAP web service. If you would like to parse a WSDL file to generate java classes, you can use the wsimport tool. This 'wsimport' tool comes with the JDK (Java Development Kit) and resides in the JDK bin directory. To generate the java classes from the WSDL, follow the steps mentioned below. - Article authored by Manika Paul Chowdhury on .

The Web Services Description Language (WSDL) is an XML based interface definition language that is used for describing the functionality offered by a SOAP web service. If you have a WSDL file and you want to generate java classes (.java and .class) from it, there are number of ways.

 

In this quick 'how-to' article, we will learn how to generate java classes using the 'wsimport' command that by default comes with JDK.

 

How to parse a WSDL file using 'wsimport' tool and generate java classes?

 

If you would like to parse a WSDL file to generate java classes, you can use the wsimport tool. This 'wsimport' tool comes with the JDK (Java Development Kit) and resides in the JDK bin directory. To generate the java classes from the WSDL, follow the steps mentioned below:

  1. Open the Run dialog, type cmd and hit Enter to open the Console Window.
  2. Enter the following command to navigate to the JDK 'bin' directory:

    cd   '%JAVA_HOME%\bin'

  3. Now enter the following command by properly filling the [TARGET_NAMESPACE], [SOURCE_DIRECTORY], [OUTPUT_DIRECTORY] and [WSDL_URL] in the below console command to start generating the java files:

    wsimport -keep -p [TARGET_NAMESPACE] -s [SOURCE_DIRECTORY] -d [OUTPUT_DIRECTORY] [WSDL_URL]

 

Points to note that:
   - The -keep argument is used to keep the generated files.
   - The -p optional argument is used to specify the target namespace.
   - The -s optional argument is used to specify where to place the generated source files.
   - The -d optional argument is used to specify where to place the generated output files.

 

We do have another approach to parse and generate java classes from WSDL. That uses JAX-WS Maven Plugin. Check it out and learn how to use it.

 

 

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.