【问题标题】:ClassNotFound: Xerces SAXParserFactoryImpl when running in Wildfly 8.2ClassNotFound:在 Wildfly 8.2 中运行时 Xerces SAXParserFactoryImpl
【发布时间】:2016-11-02 19:44:15
【问题描述】:

我正在运行 Wildfly 8.2.0 并进行一些 XML 配置文件解析。我的想法是我将能够使用我捆绑的 xercesImpl.jar 来提供 JAXP SAXParserFactoryImpl。

在 Wildfly 之外运行逻辑时,我能够成功地使用 SAXParserFactoryImpl 进行解析。这个工厂是通过设置系统属性找到的:

System.setProperty("javax.xml.parsers.SAXParserFactory",
                   "org.apache.xerces.jaxp.SAXParserFactoryImpl");
SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();

部署我的 EAR 后,我收到以下错误:

...: javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found.
..
..
...: Caused by: java.lang.ClassNotFoundException: org/apache/xerces/jaxp/SAXParserFactoryImpl
..
..

知道 Wildfly 从 wildfly/modules/system/layers/base/org/apache/xerces/main/xercesImpl-2.9.1-jbossas2.jar 运行自己的 Xerces,我尝试了以下方法:




[1] 使用 Wildfly 的 xercesImpl-2.9.1-jbossas2.jar ... 没有变化

(来源:jboss-deployment-structure.xml 的 Wildfly 文档)

在 jboss-deployment-structure.xml 中:

<jboss-deployment-structure>
    <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
    <deployment>
        ...
    </deployment>
</jboss-deployment-structure>

EAR 内容:

lib/
    ...(removed xercesImpl.jar)...
META-INF/
    application.xml // Information about EJB that uses xercesImpl.jar
    jboss-deployment-structure.xml




[2] 忽略 Wildfly 的 xercesImpl-2.9.1-jbossas2.jar ... 没有变化

(来源:https://developer.jboss.org/thread/259010?start=0&tstart=0

在 jboss-deployment-structure.xml 中:

<jboss-deployment-structure>
    <ear-subdeployments-isolated>true</ear-subdeployments-isolated>
    <deployment>
        <exclusions>
            <module name="org.apache.xerces" />
        </exclusions>
        ...
    </deployment>
</jboss-deployment-structure>

EAR 内容:

lib/
    xercesImpl.jar
    ...(many more jars)...
META-INF/
    application.xml // Information about EJB that uses xercesImpl.jar
    jboss-deployment-structure.xml




[3] 明确将 Wildfly 的 xerces 包含为一个模块...没有变化

(来源:https://developer.jboss.org/thread/239969

在 jboss-deployment-structure.xml 中:

<jboss-deployment-structure>
    <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
    <deployment>
        <dependencies>  
              <module name="org.apache.xerces" /> 
              ...
        </dependencies>  
    </deployment>
</jboss-deployment-structure>

EAR 内容:

lib/
    ...(removed xercesImpl.jar)...
META-INF/
    application.xml // Information about EJB that uses xercesImpl.jar
    jboss-deployment-structure.xml  




[4] 为 JAXP 解析器声明 Java 属性 ... 无变化

启动 Wildfly 时:

./standalone.sh -c standalone-full.xml -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl

在standalone-full.xml中

<system-properties>
    <property name="javax.xml.parsers.SAXParserFactory" value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
</system-properties>

(注意:通过尝试 [1]、[2]、[3] 尝试了此属性)




[5] 将 Xerces 路径添加到 jboss-deployment-structure ... 无变化

(来源:developer.jboss.org/message/717927#717927)

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <system>
                <paths>
                    <path name="org/apache/xerces/jaxp"/>
                </paths>
            </system>
            ...
        </dependencies>
    </deployment>
</jboss-deployment-structure>

【问题讨论】:

    标签: jakarta-ee jboss wildfly ear xerces


    【解决方案1】:

    尝试变体 3,但将 export="true" 添加到依赖项 我想您尝试使用 ejb 或战争中的 javax.xml.parsers.SAXParserFactory.newInstance()。子部署看不到 ear 的依赖模块。您必须明确地进行导出。

    【讨论】:

      【解决方案2】:

      问题最终是包含尝试加载 SAXParserFactoryImpl 的 EJB 的线程的类加载器无法访问它。为了解决这个问题,我必须找到一个具有 SAXParserFactoryImpl 可见性的类加载器的线程(恰好在我的 MDB 上)并在有问题的 bean 上手动设置它。我从来没有确定到底发生了什么,但这是一个快速而肮脏的工作。

      【讨论】:

        【解决方案3】:

        经过大量RND终于找到了解决办法。 这里是:

        1) 复制您的 XercesImpl-X.x.x.jar 并将其粘贴到 /jre/lib/ 例如:- 对我来说--> C:\Program Files\Java\jdk1.8.0_131\jre\lib 2)在lib中创建一个新文件夹“endorsed”。 3) 将 jar 文件粘贴到“endorsed”文件夹中 4) 重新启动服务器,xerces 地狱消退。

        如果解决方案对您有用,请告诉我。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-03-23
          • 1970-01-01
          • 1970-01-01
          • 2019-01-14
          • 2015-05-31
          • 1970-01-01
          • 2015-01-28
          • 2016-10-31
          相关资源
          最近更新 更多