Friday, May 11, 2007

How To Fix LinkageError when using JAXB with JDK 1.6

If you run across an error like this when trying to use JAXB:

java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI
(from jar:file:/somedirectory/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/)

It's actually a very simple fix, but painful enough to warrant a post. Put the jaxb-api.jar that you're trying to use into JDK_HOME/jre/lib/endorsed. If the endorsed directory doesn't exist, make it. This is apparently only a problem with JDK 1.6, not with JDK 1.5.

15 comments:

  1. Thanks for the post. The error is NOT resolved if one uses Tomcat (I use v. 5.5.1.7). I have tried putting the jaxb-api.jar file in the Tomcat ...\common\endorsed dir but to no avail.

    Any comments?

    ReplyDelete
  2. I tried this fix for Tomcat 6.0.14 on Fedora 6 and it didn't work. After looking at the /bin scripts it seems that the default endorsed directory is: $CATALINA_HOME/endorsed. Copying jaxb-api-2.1.jar to this directory fixes the symptom you show above for my situation. I wish the Tomcat 6 doc was better... :-/

    ReplyDelete
  3. Should also point out that, under Windows, the correct spot for that jaxb-api-2.1.jar file is: %CATALINA_HOME%\common\endorsed. Same version--6.0.14--as the Tomcat version that I just commented on.

    ReplyDelete
  4. Fixed mine with Peter's comment. Thanks peter and this post's author too.

    ReplyDelete
  5. thank's Peter. It works for me.
    I use Apache Tomcat 6.0.14 installed by NetBeans 6.0.1 .

    ReplyDelete
  6. Thanks for taking the time to post this. Fixed my problem!

    ReplyDelete
  7. It is really great help by peter on web

    ReplyDelete
  8. Man, You saved my day. I was adding that directory to Java_home/lib and apparently it wasn't working..

    ReplyDelete
  9. this also problem with JDK1.7 and
    thank you very much ...

    ReplyDelete
  10. How is the JAXB Linkage problem fixed inside an applet? After all, one can't go around copy jars into specific folder for anonymous users on the web.

    ReplyDelete
  11. Im using Tomcat 6 on Windows but I don't have the common/endorsed dir... where should I put it?

    ReplyDelete