在 maven jaxb codegen 期间将 DTMManagerDefault 转换为 DTMManager 时出现 ClassCastException

发布于 2024-09-25 17:44:05 字数 2135 浏览 2 评论 0原文

当尝试运行使用 jaxb2 插件执行 JAXB codegen 的 Maven 构建时,我遇到了一个奇怪的问题(请参阅下面的 stacktrace)。我能想到的最好的情况是,DTMManager 的一些实现是从与 xalan-2.7.1 中的 JAR 不同的 JAR 加载的;但是,我已经验证用于运行 jaxb:generate 目标的类路径只有一个包含 DTMManager 或 DTMManagerDefault 的 xalan-2.7.1.jar - 所以我不知道还有什么可能妨碍。

最后一个数据点:我们的构建指定了一个“快照”配置文件,它实际上仅用于 JAR 源(使用 maven-source-plugin)并将其作为工件发布。我上面描述的故障场景发生在除默认配置之外还指定了此配置文件时。

我正在使用在 Linux x64 (Fedora 13) 上的 Sun 64 位 JDK 1.6.0_21 上运行的 Maven 2.2.1 - 请参阅下面的堆栈跟踪以获取“mvn -v”信息。

关于问题可能是什么和/或如何调试它有什么想法吗?在过去的几天里,这一直让我感到悲伤,现在它阻碍了进展:(

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"

I'm having a strange problem when trying to run a maven build that uses the jaxb2 plugin to do JAXB codegen (see stacktrace below). The best that I can figure is that there's some implementation of DTMManager that's being class loaded from a different JAR than the one in xalan-2.7.1; however, I have verified that the classpath that is used for running the jaxb:generate goal only has the one xalan-2.7.1.jar that contains a DTMManager or a DTMManagerDefault - so I have no clue what else might be getting in the way.

One final data point: our build specifies a 'snapshot' profile, which really only serves to also JAR up the sources (using maven-source-plugin) and publish them as artifacts. The failure scenario I described above only occurs when this profile is specified in addition to the default.

I'm using Maven 2.2.1 running on Sun's 64-bit JDK 1.6.0_21 on Linux x64 (Fedora 13) - see below the stacktrace for the 'mvn -v' info.

Any ideas on what the problem may be and/or how to go about debugging it? This has been causing me grief for the past few days and it's now blocking 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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌︼了一个春 2024-10-02 17:44:05

解决方案是在类路径中搜索 Xalan 和 xercesImpl 的所有依赖项。应排除这些依赖性。

更新

我找到了这样的答案 - 请参阅http://www.mail-archive.com/[电子邮件受保护]/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

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

Updated

I found an answer like this - see http://www.mail-archive.com/[email protected]/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
蓝戈者 2024-10-02 17:44:05

要在 Maven 中排除 xalanxercesImpl 依赖项:

    <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>

另请参阅 https://community.jboss.org/wiki/FreeMarkerAndJBossAS7

To exclude the xalan and xercesImpl dependencies 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 .

小梨窩很甜 2024-10-02 17:44:05

对我来说,设置以下 JVM 属性是有效的。

-Dorg.apache.xml.dtm.DTMManager=org.apache.xml.dtm.ref.DTMManagerDefault

For me setting following JVM property worked.

-Dorg.apache.xml.dtm.DTMManager=org.apache.xml.dtm.ref.DTMManagerDefault
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文