JAXB在JDK1.6中的解决方案(但最后我没有成功,所以我重装成JDK1.5来实现)

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.

我用 JDK1.6 的方法 ( 使用的是 jboss5.0 里的 jaxb-api) 解决不了 , 后来再装了 1.5 后问题解决

 

 

7.1.2. Using JAXB 2.1 with JavaSE 6

JavaSE 6 comes with JAXB 2.0 API in rt.jar . Therefore, using JAXB 2.1 with JavaSE 6 requires one to override a portion of rt.jar with the new API. There are several ways to do this:

  1. Place the 2.1 jaxb-api.jar into $JRE_HOME/lib/endorsed . This essentially makes your JRE to "JRE 6 + JAXB 2.1". This won't affect any other applications that use this JRE, and it's easy. On the other hand, in various scenarios you may not be able to alter the JRE.
  2. Use the system property java.endorsed.dirs when you launch your application, and have it point to the directory that contains the 2.1 jaxb-api.jar . This allows you use use JAXB 2.1 without modifying the JRE. Make sure not to include any other JAXB RI jar files (such as jsr173-api.jar or jaxb-impl.jar .)
  3. Implement a custom ClassLoader and block delegation to javax.xml.bind package, so that code running inside this class loader will load the JAXB API from elsewhere. This is a very advanced approach.

No matter which approach you take, make sure not to include jar files other than jaxb-api.jar . Doing so, for example including jaxb-xjc.jar , may result in classloading related errors such as "taskdef A class needed by class com.sun.tools.xjc.XJCTask cannot be found: org/apache/tools/ant/...."

See the endorsed directory mechanism for more details.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值