【问题标题】:Using latest Xerces with Eclipse RCP application将最新的 Xerces 与 Eclipse RCP 应用程序一起使用
【发布时间】:2012-09-29 17:24:36
【问题描述】:

我正在尝试在 Eclipse RCP 应用程序中使用 Xerces 2.11.0,但是从我尝试过的所有内容来看,我不知道该怎么做。更复杂的是,我也在尝试使用 Batik 1.7。

我已经为 Xerces 和 xml-apis 创建了自己的包,我已经将 Batik 使用的其他 W3C DOM 接口添加到了我的 xml-apis 包中。

蜡染中出现的第一个问题

java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

其根本原因似乎是因为 org.w3c.dom 包含在 JRE 中并通过 org.eclipse.osgi(system.bundle)公开。这似乎胜过任何其他想要提供该软件包的捆绑包。

试图在任何其他人之前使用 require-bundle 和我的 bundle 来影响系统,或使用带有显式版本的 import-package 会导致类似的错误

java.lang.LinkageError: loader constraint violation: loader
       (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) 
        previously initiated loading for a different type with name
        "org/w3c/dom/Document"

更改 org.osgi.framework.system.packagesorg.osgi.framework.bootdelegation 参数以删除 org.w3c.dom 并将我的包添加到 osgi.framework.extensions,会导致类似的错误

java.lang.LinkageError: loader constraint violation in interface itable
       initialization: when resolving method 
       "javax.xml.parsers.DocumentBuilder.setErrorHandler(
                 Lorg/xml/sax/ErrorHandler;)V" the class loader 
       (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader)
       of the current class, org/apache/log4j/xml/DOMConfigurator, and the 
       class loader (instance of <bootloader>) for resolved class, 
       javax/xml/parsers/DocumentBuilder, have different Class objects for the
       type rrorHandler;)V used in the signature

我也尝试过使用 java.endorsed.dirs,这会让事情很快崩溃。

我错过了什么或可能做错了什么?

【问题讨论】:

    标签: eclipse osgi eclipse-rcp xerces


    【解决方案1】:

    我想我找到了解决办法。

    我已经修改了我的 xml-apis 包,使它成为一个片段,由 system.bundle 托管。

    我还修改了我的 Xerces 包以导入包,而不是需要 xml-apis 包(最初这样做是为了说服 xerces 使用正确的包)。

    从我所做的测试来看,这似乎足以让每个包找到 org.w3c.dom 包的相同实现,其中包含所有正确的类。

    【讨论】:

      【解决方案2】:

      我们曾经在 jdk 1.4 上使用 DOM 级别 3 时遇到过类似的问题,我认为背书的 dirs 是唯一可行的解​​决方案,因为您需要覆盖 jdk 中的 DOM API。

      我们无法再次面对这条路线,因此删除了对 ElementTraversal 的引用并手动构建了 Xerces,问题就消失了。如果 Batik 使用 ElementTraversal,那不是一个选择。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-13
        • 2019-02-12
        • 1970-01-01
        • 1970-01-01
        • 2014-08-13
        • 2011-04-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多