Fixing wadl2java

On a recent project, I was given a WADL file and wanted a way to quickly knock out some client code for calling the web service described by the file.

I quickly came across two tools that, annoyingly, have the same name: wadl2java from Java.net and wadl2java from Apache CXF. Since I have no experience with Apache CXF, I decided to try the Java.net tool. The only problem? Every time I try to run it, I get the following error:

Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
        at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122)
        at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
        at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:69)
        at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:80)
        at org.jvnet.ws.wadl2java.Wadl2Java.generateEndpointClass(Wadl2Java.java:618)
        at org.jvnet.ws.wadl2java.Wadl2Java.process(Wadl2Java.java:472)
        at org.jvnet.ws.wadl2java.Main.main(Main.java:143)
Caused by: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:188)
        at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:62)
        at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:155)
        at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:105)
        ... 6 more

After an afternoon of troubleshooting, it turns out that this is a known bug in wadl2java 1.1.3 that occurs on vanilla installs of JDK6 or JDK7, and has been around since October 2012.

To work around the problem, you need to do two things:

  1. Add jersey-client-1.13.jar to wadl2java’s lib directory.
  2. Add jersey-core-1.13.jar jersey-client-1.13.jar to the Class-Path in wadl-cmdline-1.1.3.jar‘s MANIFEST.MF file.

If you don’t want to do Step 2 yourself, you can download my modified version of wadl-cmdline-1.1.3.jar instead. Hopefully version 1.1.4 will be released soon, but until then this should get things up and running.