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.

 

 


Kunal Chowdhury

About the Author

Solution Architect & Former Microsoft MVP

Kunal Chowdhury is an enterprise solution architect and former multi-year Microsoft MVP. He is the author of three technical books: Windows Presentation Foundation Development Cookbook, Mastering Visual Studio 2017, and the Mastering Visual Studio 2019.

He publishes technical and non-technical articles on .