ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl无法转换为javax.xml.parsers.DocumentBuilderFactory [英] ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory

查看:64
本文介绍了ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl无法转换为javax.xml.parsers.DocumentBuilderFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与有关Xerces依赖地狱的许多讨论有关,但我似乎无法解决.

This problem ties in with the many discussions about the Xerces dependency hell, but I can't seem to solve it.

我正在尝试将LaTeX代码导出为Java中的PDF.我的代码是Cytoscape 3.4的OSGI软件包的一部分,并由Maven管理和构建.LaTeX库是 jlatexmath (1.0.6),要写入SVG和PDF,我想尝试apache fop (0.95)库.

I'm trying to export LaTeX code to PDF in Java. My code is part of an OSGI bundle for Cytoscape 3.4 and is managed and built with Maven. The LaTeX library is jlatexmath (1.0.6) and to write to SVG and PDF I want to try the apache fop (0.95) libs.

Fop依赖于整个 batik 库,而这些库又依赖于 xml-apis (1.3.04).

Fop is depending on a whole range of batik libraries, which in turn depend on xml-apis (1.3.04).

包含 xml-apis 时,出现此错误:

java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
        at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
        at org.scilab.forge.jlatexmath.TeXFormulaSettingsParser.<init>(TeXFormulaSettingsParser.java:74)

这是可以理解的,因为JRE中包含的 DocumentBuilderFactory 的实现应该是 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl .

Which is understandable as the implementation of DocumentBuilderFactory is supposed to be com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl as included in the JRE.

当我排除xml-apis和xml-apis-ext库时,出现另一个错误:

When I exclude the xml-apis and xml-apis-ext libs, I get another error:

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>fop</artifactId>
    <version>0.95</version>
    <exclusions>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis-ext</artifactId>
        </exclusion>
    </exclusions>
</dependency>


java.lang.ClassNotFoundException: org.w3c.dom.Document not found by... [115]
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
        at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

这很奇怪,因为 org.w3c.dom.Document 也应该位于JRE中.

Which is weird, as org.w3c.dom.Document should also just be in the JRE.

那么,如何强制Java使用Java中包含的类,而不是查找从Maven依赖项加载的类?

So, how can I force Java to use the classes included in Java instead of looking for the ones loaded from the Maven dependencies?

推荐答案

您的捆绑包需要导入软件包 org.w3c.dom .您必须导入捆绑软件所依赖的所有软件包,但以 java开头的单独软件包除外. java.lang java.net 等.

Your bundle needs to import the package org.w3c.dom. You must import all packages that your bundle depends on, with the solitary exception of packages starting with java., e.g. java.lang, java.net etc.

这篇关于ClassCastException:org.apache.xerces.jaxp.DocumentBuilderFactoryImpl无法转换为javax.xml.parsers.DocumentBuilderFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆