How to generate java client classes from WSDL

  • 05 April 2016
  • ADM

 

How to generate java client classes from WSDL - images/logos/java.jpg

 

To generate the client classes will use wsimport tool. This tool will parse a WSDL file and all required files for web service client to access the published web services. This tool is available in the JDK installation folder: $JDK/bin.

Note: to learn more about how to create a WSDL file, please follow How to create WSDL file with Eclipse tutorial.

The minimum command line would be:

$ wsimport -p com.admfactory.ws -s src wsdl/InvoiceService.wsdl -wsdllocation wsdl/InvoiceService.wsdl -verbose

Parameters used

  • -p specifies the target package;
  • -s specify where to place generated source files;
  • -wsdllocation @WebServiceClient.wsdlLocation value
  • -verbose output messages about what the compiler is doing

For full parameters list run the command:

$ wsimport -h

Output

$ wsimport -p com.admfactory.ws -s src wsdl/InvoiceService.wsdl -wsdllocation wsdl/InvoiceService.wsdl -verbose
parsing WSDL...



Generating code...

com/admfactory/ws/BalanceInqueryRequest.java
com/admfactory/ws/BalanceInqueryResponse.java
com/admfactory/ws/InvoiceService.java
com/admfactory/ws/InvoiceService_Service.java
com/admfactory/ws/ObjectFactory.java
com/admfactory/ws/PaymentRequest.java
com/admfactory/ws/PaymentResponse.java
com/admfactory/ws/ReversalRequest.java
com/admfactory/ws/ReversalResponse.java
com/admfactory/ws/Status.java
com/admfactory/ws/package-info.java

Compiling code...

javac -d /Volumes/data/javaWorkspace/WSDLFile/. -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/classes -Xbootclasspath/p:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/rt.jar /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/BalanceInqueryRequest.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/BalanceInqueryResponse.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/InvoiceService.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/InvoiceService_Service.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/ObjectFactory.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/PaymentRequest.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/PaymentResponse.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/ReversalRequest.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/ReversalResponse.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/Status.java /Volumes/data/javaWorkspace/WSDLFile/src/com/admfactory/ws/package-info.java

The files were generated using Mac OS, but will work also for Windows OS.

 

References

For more details about wsimport use the following link: