Class Cast exception: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

懵懂的女人 提交于 2019-12-22 06:37:29

问题


I'm struck with a problem in jboss. When I try to deploy my .war into the server, I get this following error,

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,

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.

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?

Update

I did as suggested here and 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 :(


回答1:


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.

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.




回答2:


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

See http://www.coderanch.com/t/523519/JBoss/Cast and http://www.mastertheboss.com/jboss-application-ser...oss-5-classloading-issues.html



来源:https://stackoverflow.com/questions/4278213/class-cast-exception-com-sun-org-apache-xerces-internal-jaxp-documentbuilderfac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!