java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to org.apache.xml.dtm.DTMManager

Phi picture Phi · Jul 17, 2015 · Viewed 7.8k times · Source

I would like use Primefaces and Myfaces on my application. However there is an exception.

00:31:01,292 SEVERE [org.primefaces.config.ConfigContainer] (http--0.0.0.0-8081-1) Could not load or parse web.xml: java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to org.apache.xml.dtm.DTMManager
    at org.apache.xml.dtm.DTMManager.newInstance(DTMManager.java:137) [xalan.jar:4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)]
    at org.apache.xpath.XPathContext.<init>(XPathContext.java:102) [xalan.jar:4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)]
    at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:115)
    at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:99)
    at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:184)
    at org.primefaces.config.ConfigContainer.initErrorPages(ConfigContainer.java:314) [primefaces-5.2.jar:5.2]
    at org.primefaces.config.ConfigContainer.initConfigFromWebXml(ConfigContainer.java:291) [primefaces-5.2.jar:5.2]
    at org.primefaces.config.ConfigContainer.<init>(ConfigContainer.java:88) [primefaces-5.2.jar:5.2]
    at org.primefaces.context.DefaultApplicationContext.<init>(DefaultApplicationContext.java:35) [primefaces-5.2.jar:5.2]
    at org.primefaces.context.DefaultRequestContext.getApplicationContext(DefaultRequestContext.java:227) [primefaces-5.2.jar:5.2]
    at org.primefaces.metadata.transformer.MetadataTransformerExecutor.processEvent(MetadataTransformerExecutor.java:50) [primefaces-5.2.jar:5.2]
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:43) [myfaces-api-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl._traverseListenerList(ApplicationImpl.java:2471) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl.access$000(ApplicationImpl.java:120) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl$SystemListenerEntry.publish(ApplicationImpl.java:2662) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:601) [myfaces-bundle-2.1.12.jar:2.1.12]
    at javax.faces.component.UIComponentBase._publishPostAddToViewEvent(UIComponentBase.java:235) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:215) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component._ComponentFacetMap.setNewParent(_ComponentFacetMap.java:178) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component._ComponentFacetMap.put(_ComponentFacetMap.java:145) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component._ComponentFacetMap.put(_ComponentFacetMap.java:33) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component.UIViewRoot._getComponentResources(UIViewRoot.java:623) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component.UIViewRoot.addComponentResource(UIViewRoot.java:157) [myfaces-api-2.1.12.jar:2.1.12]
    at org.apache.myfaces.tomahawk.application.ResourceViewHandlerWrapper$1.processEvent(ResourceViewHandlerWrapper.java:95) [tomahawk20-1.1.14.jar:1.1.14]
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:43) [myfaces-api-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl._traverseListenerListWithCopy(ApplicationImpl.java:2517) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:594) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:616) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:222) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117) [myfaces-bundle-2.1.12.jar:2.1.12]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197) [myfaces-api-2.1.12.jar:2.1.12]
    at com.esilicon.web.jsf.FacesServletDecorator.service(FacesServletDecorator.java:62) [:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:294) [tomahawk20-1.1.14.jar:1.1.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at com.esilicon.web.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:27) [:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357) [tomahawk20-1.1.14.jar:1.1.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at com.esilicon.vms.web.admin.UserLoggedOffFilter.doFilter(UserLoggedOffFilter.java:40) [:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_22]

How is this caused and how can I solve it?

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.

Answer

BalusC picture BalusC · Jul 17, 2015

Your webapp's runtime classpath is polluted with multiple different versioned JAXP libraries. In your specific case, the mentioned classes are loaded by different classloaders (one via server itself and other via webapp itself) and therefore couldn't be cast to each other.

Simply cleanup and remove the duplicate JAXP-related libraries in classpath (such as Xalan in your specific case). This covers among others the webapp's /WEB-INF/lib folder and server's /lib folder. Do note that the average server already ships with JAXP out the box. So you do not need to provide those along your webapp at all.

This is not a JSF specific problem.