Skip to main content

Running JAXB/WS 2.1 tools on JDK 6

Posted by kohsuke on February 5, 2007 at 5:19 PM PST

As Jave SE 6 adoption increases, it's getting more and more painful that you can't run JAXB/WS 2.1 tools in a straight-forward fashion on JavaSE; since we care about development experience, we decided that it's time to fix this.

The crux of the problem is to load JAXB/WS 2.1 API in JavaSE 6, where 2.0 APIs are in the bootstrap classloader. So I needed to pull off some dangerous classloader trick to make this work, but the good news is that as an user, you wouldn't see any of this. It will just work (TM).

With this change, when you run xjc on Java 1.4. You get this (actually it's been like this since JAXB RI 2.0):

$ java -jar path/to/2.1/jaxb-xjc.jar test.xsd
XJC requires JDK 5.0 or later. Please download it from http://java.sun.com/j2se/1.5/

Much better than "java.lang.UnsupportedClassVersionError: (Unsupported major.minor version 49.0)".

When you run it on Java 1.5, you get this, as expected:

$ java -jar path/to/2.1/jaxb-xjc.jar test.xsd
parsing a schema...
compiling a schema...
generated\Booking.java
generated\Company.java
generated\Contact.java
generated\ObjectFactory.java
generated\Student.java

... and when you run it on JavaSE 6, you'll get this:

$ java -jar path/to/2.1/jaxb-xjc.jar test.xsd
parsing a schema...
compiling a schema...
generated\Booking.java
generated\Company.java
generated\Contact.java
generated\ObjectFactory.java
generated\Student.java

No endorsed directory mechanism like explained here. No touching JRE/JDK.

The same applies to Ant tasks. Just follow the example illustrated in the release note, and it will just work with JavaSE 6.

The same also applies to wsgen and wsimport. These changes are in JAXB/WS RI 2.1 nightlies. I wish we thought about doing this before JAX-WS RI 2.1 release...

... continues to to the follow-up post

Related Topics >>