java 类转换异常:com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4278213/
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
Class Cast exception: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
提问by Ozyman
I'm struck with a problem in jboss. When I try to deploy my .war into the server, I get this following error,
我对 jboss 中的一个问题感到震惊。当我尝试将我的 .war 部署到服务器时,出现以下错误,
java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.SAXParserF
actoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.SAXParserF
actoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
from which, it is quite evident that there is a clash of libraries. So, I removed the jar file which contains xerces, which happened to by jaxp-ri-1.4.1.jar. Now, when I try to re-deploy, I get this new error,
从中,很明显存在库的冲突。因此,我删除了包含 xerces 的 jar 文件,这恰好是 jaxp-ri-1.4.1.jar。现在,当我尝试重新部署时,出现了这个新错误,
java.lang.NullPointerException
at org.apache.commons.digester.Digester.getXMLReader(Digester.java:944)
at org.apache.commons.digester.Digester.parse(Digester.java:1765)
at org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java
where it is complaining that it can't find the xml parsers.
它抱怨找不到 xml 解析器的地方。
So, now my questions is that does anybody know what can be a solution. Any jaxp jar file that doesn't contain the xerces package?
所以,现在我的问题是有人知道什么是解决方案。任何不包含 xerces 包的 jaxp jar 文件?
Update
更新
I did as suggested hereand now I have a new error,
java.lang.NoClassDefFoundError: Could not initialize class com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl
which is a class from one of the jars I deleted which contains SaxParserFactory :(
这是我删除的其中一个 jar 中的一个类,其中包含 SaxParserFactory :(
采纳答案by Vineet Reynolds
It appears that you've deleted the wrong JAR. The original ClassCastException was reported when an instance of SAXParserFactoryImpl (which is a subtype of SAXParserFactory) is being cast to SAXParserFactory.
您似乎删除了错误的 JAR。当 SAXParserFactoryImpl(它是 SAXParserFactory 的子类型)的一个实例被转换为 SAXParserFactory 时,会报告原始 ClassCastException。
The exception is more likely to be due to the fact that there are two instances of SAXParserFactory rather than two instances of SAXParserFactoryImpl being loaded in the JVM. At the time of casting, the SAXParserFactory loaded by a different classloader was returned resulting in the exception. The fix therefore is to identify JARs in your classpath that have conflicting versions of SAXParserFactory. Removing the parser implementation itself might not be wise, if Commons Digester is looking for a particular implementation.
该异常更有可能是因为在 JVM 中加载了 SAXParserFactory 的两个实例而不是 SAXParserFactoryImpl 的两个实例。在转换时,由不同的类加载器加载的 SAXParserFactory 被返回,导致异常。因此,修复方法是识别类路径中具有 SAXParserFactory 版本冲突的 JAR。如果 Commons Digester 正在寻找特定的实现,那么删除解析器实现本身可能并不明智。
回答by patrycja
I'm guessing... You're using JBoss 5.1. If so then it's xml parser and classloading issue. You must define jboss-classloading.xml
我猜...您正在使用 JBoss 5.1。如果是这样,那就是 xml 解析器和类加载问题。您必须定义 jboss-classloading.xml
See http://www.coderanch.com/t/523519/JBoss/Castand http://www.mastertheboss.com/jboss-application-ser...oss-5-classloading-issues.html
见http://www.coderanch.com/t/523519/JBoss/Cast和http://www.mastertheboss.com/jboss-application-ser...oss-5-classloading-issues.html