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.
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:
- Open the Run dialog, type cmd and hit Enter to open the Console Window.
- Enter the following command to navigate to the JDK 'bin' directory:
cd '%JAVA_HOME%\bin'
- 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.