The Source for Java Technology Collaboration
User: Password:



Kohsuke Kawaguchi

Kohsuke Kawaguchi's Blog

Running JAXB/WS 2.1 tools on JDK 6

Posted by kohsuke on February 05, 2007 at 05:19 PM | Comments (19)

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


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Sounds like you used the PreferredClassloader trick from Jini. Loads some classes locally rather than delegating? Jini does this specifically due to issues like this one, but only with remote code downloaded from a URL codebase.

    Posted by: voidmain on February 05, 2007 at 07:13 PM

  • Well, I didn't copy anything from anywhere, but I'm not surprised if the same technique has been used elsewhere already.

    Posted by: kohsuke on February 05, 2007 at 07:53 PM

  • Any chance that you'd consider writing a blog entry about this "dangerous classloader trick"? :-)

    Posted by: quintesse on February 06, 2007 at 01:25 AM

  • Does this trick only work with the JAXB tools? Is it possible to use the same trick so that when I run an application which uses JAXB 2.1 on Java 6 it Just Works? Thanks, Tom

    Posted by: tomwhite on February 06, 2007 at 08:33 AM

  • Thanks for your questions. See my follow-up post.

    Posted by: kohsuke on February 06, 2007 at 10:01 AM

  • Any chance you will include the XJCTask in J2SE in the future? I found it a bit confusing that xjc is included in J2SE and not XJCTask. The documentation on ant and xjc usage was not very helpful here. I finally figured it out (thanks Google) but I stil think it is not so developer friendly.

    Posted by: gwalther on March 20, 2007 at 01:16 PM

  • Traditionally JavaSE doesn't include any Ant task implementation. For example, there's no javac task.

    What we can consider more easily is to offer a stand-alone download of the ant task for JavaSE. Or maybe talk with Ant folks to see if they can make it one of the core tasks.

    Posted by: kohsuke on March 21, 2007 at 07:26 PM

  • Well, I just tried the latest nightly and it doesn't "just work" for me. I'm trying to get it to work with NetBeans. The first time I tried it, it gave me a message about adding "xendorsed="true"" to wsgen which I did. Now, I'm seeing the following error. Note, I've seen the "Error starting..." error in the past for other reasons with Java 5. It would be helpful if it gave a more meaningful error message. wsgen-init-nonJSR109: wsgen-ReservationsWebService-nonJSR109: J:\Reservations\ReservationsWebService\nbproject\build-impl.xml:310: Error starting wsgen: BUILD FAILED (total time: 8 seconds)

    Posted by: jemiller1 on April 05, 2007 at 02:05 PM

  • Well, I'm back to using Java 5. I vote for the removal of JAX-WS from Java 7. All this endorsed directories business is highly frustrating. Bundling JAX-WS with the JRE is unhelpful to say the least. I was able to get wsgen to work by putting jaxws-api.jar and jaxb-api.jar in my $JAVA_HOME/jre/lib/endorsed directory, but, Tomcat seems to ignore this. Tomcat has a $CATALINA_HOME/common/endorsed directory, but, putting the files there didn't seem to make a difference.

    Posted by: jemiller1 on April 05, 2007 at 02:55 PM

  • I agree that "Error starting wsgen" message is not very helpful, but I'm not sure who's producing it. Is it Ant, NetBeans, or the wsgen task? Can you run ant with -debug to get the stack trace?

    As for Tomcat, looking at catalina.sh, it looks like you need to set $JAVA_ENDORSED_DIRS environment variable to $JAVA_HOME/jre/lib/endorsed.

    I think going forward the direction with JAXB/WS is more like not releasing versions out of sync from JavaSE. That eliminates any endorsed directory business.

    Posted by: kohsuke on April 05, 2007 at 03:11 PM

  • Hi Kohsuke, I've filed https://jax-ws.dev.java.net/issues/show_bug.cgi?id=304 for the issue mentioned by jemiller1. It seems to me that the cause is either in JAXWS-RI or JAXB (according to the output from ant). There's also simple testcase for you ;-) --lukas

    Posted by: jungicz on April 11, 2007 at 07:58 AM

  • @kohshuke $JAVA_ENDORSED_DIRS doesnt seem to work for me but putting jaxb-api.jar in $JAVA_HOME/jre/lib/ext works. Notice that u need remove jaxb-impl.jar from your project.

    Posted by: hallis on October 25, 2007 at 03:33 AM

  • Putting jaxb-api.jar in $JAVA_HOME/jre/lib/ext does NOT work for me. Maybe because I don't know where to remove jaxb-impl.jar from my project. Also, what does C:\java -jar path/to/2.1/jaxb-xjc.jar test.xsd do? Does one go to the home_dir of JAX-WS 2.1/lib for the jaxb-xjc.jar? Then what is the schema file test.xsd for? How is it used to solve the problem? Please give more details.

    Posted by: bllim on November 10, 2007 at 11:31 PM

  • Hi In webservices using java when we deploy it,display the Bootstrap class loader error, it requires jaxb 2.1 api.Why it requires jaxb2.1 api? Im using Netbeans 5.5.1 IDE with java 6,where i want to put those Jaxb2.1 api jars in which folder. pls help me... Thanks, Prabhu.K

    Posted by: raghavprabhu on November 16, 2007 at 01:30 AM

  • I am using JAXB 2.1.5 with JDK 1.6.0_03. I deleted the the "lib/endorsed" from jdk and jre directories. When I ran the application I got the following error. java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/C:/${ProjectDirectory}/lib/jaxb/lib/jaxb- impl.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/) at com.sun.xml.bind.v2.model.impl.ModelBuilder.(ModelBuilder.java:172) Did your changes make it to 2.1.5? I am trying to deploy the application without having to add the "/lib/endorsed" directories in jre and jdk. I am using GlassFish Application Server. How can I acheive this? :) Thanks, Hema.

    Posted by: hemaga on December 06, 2007 at 06:24 PM

  • What version of JAXB has this fix? I am running 2.1.3 and I get: Failure to load a plugin: "com.sun.tools.internal.xjc.addon.episode.PluginImpl is not a subclass of class com.sun.tools.xjc.Plugin. Skipping". Use the system property '-Dcom.sun.tools.xjc.Options.findServices=true' to diagnose it further Is this the problem that is supposed to be fixed?

    Posted by: russgold on December 11, 2007 at 08:38 AM

  • hemaga, if you are using GlassFish v2, it does all the things necessary to make JAXB/JAX-WS 2.1 work out of box. No work needed on your side.

    Posted by: kohsuke on December 17, 2007 at 11:48 AM

  • russgold, that actually sounds like a JDK problem. Which version of JDK are you using? Please post the output of "java -fullversion"

    Posted by: kohsuke on December 17, 2007 at 11:49 AM

  • What version of JAX-WS is this in? I am running 2.1.3, and I'm still getting the same error message: You are running on JDK6 which comes with JAX-WS 2.0 API, but this tool requires JAX-WS 2.1 API. Use the endorsed standards override mechanism (http://java.sun.com/javase/6/docs/technotes/guides/standards/), or set xendorsed="true" on .

    Posted by: jbarnum on February 27, 2008 at 03:36 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds