java LinkageError JAXB 2.0 -> 2.1 (Tomcat)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/725337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LinkageError JAXB 2.0 -> 2.1 (Tomcat)
提问by Bart van Heukelom
I'm getting this error when trying to access my webservice running inside tomcat.
尝试访问在 tomcat 中运行的网络服务时出现此错误。
Caused by: java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/C:/software/tomcat6/webapps/messaging/WEB-INF/lib/jaxb-impl-2.1.5.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/)
引起:java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/C:/software/tomcat6/webapps/messaging/WEB-INF/lib/jaxb-impl -2.1.5.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) 需要 2.1 API。使用背书目录机制将 jaxb-api.jar 放在引导类加载器中。(见http://java.sun.com/j2se/1.5.0/docs/guide/standards/)
I googled for the error and did what should solve it (I put jaxb-api.jar, version 2.1 in JDK/lib/endorsed and JDK/jre/lib/endorsed) but it doesn't appear to have any effect.
我用谷歌搜索错误并做了什么应该解决它(我将 jaxb-api.jar,2.1 版放在 JDK/lib/endorsed 和 JDK/jre/lib/endorsed 中),但它似乎没有任何影响。
I didn't have it before, and I'm not sure what was changed. I use JDK 6u10.
我以前没有它,我不确定发生了什么变化。我使用 JDK 6u10。
采纳答案by andri
Java 6u10 includes JAXB 2.1, so there is no need to include it at all (it has been included since 6u4).
Java 6u10 包含 JAXB 2.1,因此根本不需要包含它(从 6u4 开始就包含了)。
Right now it looks like you have a conflict between JAXB included with a webapp and the bundled JAXB that comes with JRE. You could try removing the JAXB jar from your webapp (C:/software/tomcat6/webapps/messaging/WEB-INF/lib/jaxb-impl-2.1.5.jar) and rely on the built-in version.
现在看起来您在 Web 应用程序中包含的 JAXB 和 JRE 附带的捆绑 JAXB 之间存在冲突。您可以尝试从您的 webapp ( C:/software/tomcat6/webapps/messaging/WEB-INF/lib/jaxb-impl-2.1.5.jar) 中删除 JAXB jar并依赖内置版本。
回答by kgiannakakis
The recommended way is to define the JAVA_ENDORSED_DIRS environmental variable. Then Tomcat will use this Java property:
推荐的方法是定义 JAVA_ENDORSED_DIRS 环境变量。然后 Tomcat 将使用这个 Java 属性:
-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS
in order to load the endorsed jars. So, create a folder, put jaxb-api.jar v2.1 there and define the environmental variable to point at that folder.
为了加载认可的罐子。因此,创建一个文件夹,将 jaxb-api.jar v2.1 放在那里并定义环境变量以指向该文件夹。
This is better than using the global endorsed directory, because it doesn't affect the whole JVM and you don't have to repeat the process, when the JRE is updated.
这比使用全局背书目录要好,因为它不会影响整个 JVM,并且您不必在更新 JRE 时重复该过程。
回答by David Rabinowitz
Is it possible you have the jaxb jars in the $JAVA_HOME/jre/lib/ext directory? Here is the definition of the bootstrap loader:
您是否可能在 $JAVA_HOME/jre/lib/ext 目录中有 jaxb jar?这是引导加载程序的定义:
Bootstrap - This class loader contains the basic runtime classes provided by the Java Virtual Machine, plus any classes from JAR files present in the System Extensions directory ($JAVA_HOME/jre/lib/ext). NOTE - Some JVMs may implement this as more than one class loader, or it may not be visible (as a class loader) at all.
Bootstrap - 该类加载器包含 Java 虚拟机提供的基本运行时类,以及系统扩展目录 ($JAVA_HOME/jre/lib/ext) 中存在的 JAR 文件中的任何类。注意 - 一些 JVM 可能将其实现为多个类加载器,或者它可能根本不可见(作为类加载器)。
(Taken form here)
(此处采用形式)
Please search for all the places where you have the jaxb jars in the system (at least jaxb-api and jaxb-impl) and make sure that they are in either the WEB-INF/lib directory of your web application or in the lib directory of the tomcat.
请搜索系统中所有包含 jaxb jar 的地方(至少是 jaxb-api 和 jaxb-impl),并确保它们位于 Web 应用程序的 WEB-INF/lib 目录或 lib 目录中的tomcat。

