ClassCastException on casting DTMManagerDefault in DTMManager during maven jaxb codegen

I had a strange problem while trying to run the maven build, which uses the jaxb2 plugin to execute the JAXB codegen (see stacktrace table below). The best I can understand is that there is some implementation of the DTMManager, which is a class loaded from a different JAR than the one that is in xalan-2.7.1; however, I checked that the path to the class that is used to run jaxb: generate the target has only one xalan-2.7.1.jar that contains the DTMManager or DTMManagerDefault, so I donโ€™t know what else could be in the way.

One data endpoint: our assembly defines a snapshot profile that really only serves JAR sources (using the maven-source-plugin) and publishes them as artifacts. The failure scenario described above only occurs when this profile is specified in addition to the default.

I am using Maven 2.2.1, running on Sun 64-bit JDK 1.6.0_21 on Linux x64 (Fedora 13) - see the stack below for information on "mvn -v".

Any ideas on what might be the problem and / or how to debug it? This has caused me grief over the past few days, and now it blocks progress :(

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) at org.apache.xpath.XPathContext.<init>(XPathContext.java:102) at org.apache.xpath.jaxp.XPathImpl.eval(XPathImpl.java:207) at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:281) at com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap(Internalizer.java:224) at com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap(Internalizer.java:289) at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:134) at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:96) at com.sun.tools.xjc.reader.internalizer.DOMForest.transform(DOMForest.java:448) at com.sun.tools.xjc.ModelLoader.buildDOMForest(ModelLoader.java:342) at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:374) at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:167) at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:113) at org.jvnet.jaxb2.maven2.XJC2Mojo.runXJC(XJC2Mojo.java:1119) at org.jvnet.jaxb2.maven2.XJC2Mojo.execute(XJC2Mojo.java:720) ... 

mvn -v:

 # mvn -v Apache Maven 2.2.1 (r801777; 2009-08-06 14:16:01-0500) Java version: 1.6.0_21 Java home: /usr/java/jdk1.6.0_21/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux" version: "2.6.33.3-85.fc13.x86_64" arch: "amd64" Family: "unix" 
+6
java maven-2 jaxb2 classcastexception
source share
2 answers

The solution is to find all the dependencies on Xalan and xercesImpl in the classpath. These dependencies should be excluded.

Update

I found an answer like this - see http://www.mail-archive.com/ dev@qpid.apache.org /msg07295.html

 Had a look at this closely and figured it was due to a classpath class due to Sun bundling an older version of Xalan jar. I have disabled this test until we come up with a decent solution. Rajith 
+13
source share

To eliminate xalan and xercesImpl in Maven:

  <dependency> <!-- ClassNotFoundException: org.jaxen.dom.DOMXPath --> <groupId>jaxen</groupId> <artifactId>jaxen</artifactId> <version>1.1.3</version> <exclusions> <exclusion> <artifactId>maven-findbugs-plugin</artifactId> <groupId>maven-plugins</groupId> </exclusion> <exclusion> <artifactId>maven-cobertura-plugin</artifactId> <groupId>maven-plugins</groupId> </exclusion> <!-- ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault -> org.apache.xml.dtm.DTMManager --> <exclusion> <artifactId>xercesImpl</artifactId> <groupId>xerces</groupId> </exclusion> <exclusion> <artifactId>xalan</artifactId> <groupId>xalan</groupId> </exclusion> </exclusions> </dependency> 

See also https://community.jboss.org/wiki/FreeMarkerAndJBossAS7 .

+3
source share

All Articles