Creating Java Classes from WSDL file using Apache Axis 2

Since I didn’t found this on the internet (but some rather outdated or complicated tutorials) here’s how to create Java class as wrapper for a given SOAP webservice.

  1. Download most recent Apache Axis 2: http://ws.apache.org/axis2/download.cgi. I used version 1.5.1
  2. Extract it to a directory of your choice
  3. On the command line, change to subdirectory bin/ and run wsdl2java.bat -uri [URL of WSDL file] (on Windows) or wsdl2java.sh -uri [URL of WSDL file] on Linux.
  4. The Java classes are created in the src/ subdirectory. Copy them into your project

To effectivly use the classes generated you must add a bunch of jars to your project dependiencies. These are found in the lib/ directory of the extracted Apache Axis distribution. You need ([version] notes a version number):

  • axis2-adb-[version].jar
  • axis2-kernel-[version].jar
  • axis2-transport-local-[version].jar
  • axis2-transport-http-[version].jar
  • axiom-api-[version].jar
  • axiom-dom-[version].jar
  • axiom-impl-[version].jar
  • commons-codec-[version].jar
  • commons-logging-[version].jar
  • commons-httpclient-[version].jar
  • httpcore-[version].jar
  • mail-[version].jar
  • neethi-[version].jar
  • wsdl4j-[version].jar
  • XmlSchema-[version].jar

Apache Axis generated a class class [Name of Webservice]Stub, e.g. for a webservice TimeOfDay it would be TimeOfDayStub. This class has all the webservice’s methods and nested classes for the method’s arguments. Everything is relatively straight forward and easy to use.

That’s it.

There is an Apache Axis Eclipse plugin for converting WSDL into Java classes, but the download URL seems broken. I also tried to use Eclipse’s WSD toolset, but this unnecessarily requires a local web server to be set up and running.

Edit: Corrected wsdl2java parameter from -url to -uri

Published: August 06 2010