kunal-chowdhury.com

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 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.

 

 


If you have come this far, it means that you liked what you are reading (How to parse a WSDL file using 'wsimport' tool and generate java classes?).

Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions.