ClassNotFound: Xerces SAXParserFactoryImpl when running in Wildfly 8.2

左心房为你撑大大i 提交于 2019-12-25 05:00:31

问题


I am running Wildfly 8.2.0 and doing some XML Config file parsing. The idea is that I'll be able to use my bundled xercesImpl.jar to provide the JAXP SAXParserFactoryImpl.

When running the logic outside of Wildfly, I am successfully able to parse with the SAXParserFactoryImpl. This factory is found by setting the system property:

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

After deploying my EAR, I receive the following error:

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

Knowing that Wildfly runs its own Xerces from wildfly/modules/system/layers/base/org/apache/xerces/main/xercesImpl-2.9.1-jbossas2.jar, I have tried the following:




[1] Use Wildfly's xercesImpl-2.9.1-jbossas2.jar ... no change

(Source: Wildfly Documentation for jboss-deployment-structure.xml)

In jboss-deployment-structure.xml:

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

EARContent:

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




[2] Ignore Wildfly's xercesImpl-2.9.1-jbossas2.jar ... no change

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

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

EARContent:

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




[3] Explicitly include Wildfly's xerces as a module ... no change

(Source: https://developer.jboss.org/thread/239969)

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

EARContent:

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




[4] Declare Java property for JAXP Parser ... no change

when launching Wildfly:

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

in standalone-full.xml

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

(Note: Tried this property with attempts [1], [2], [3])




[5] Adding Xerces Path to jboss-deployment-structure ... no change

(Source: 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>

回答1:


Try variant 3 but add export="true" to dependency I suppose you try use javax.xml.parsers.SAXParserFactory.newInstance() from ejb or war. Subdeployments don't see dependency modules of ear. You must do export explicitly.




回答2:


The problem ended up being that the classloader of the thread containing the EJB that tried to load SAXParserFactoryImpl did not have access to it. To remedy this, I had to find a thread that had a classloader with SAXParserFactoryImpl visibility (happened to be on my MDB) and manually set it on the problematic bean. I never did determine just what was happening, but this was a quick and dirty work around.




回答3:


After a lot of RND finally found the solution. Here is goes :

1) Copy your XercesImpl-X.x.x.jar and paste it in the /jre/lib/ eg:- for me --> C:\Program Files\Java\jdk1.8.0_131\jre\lib 2) Inside the lib create a new folder "endorsed". 3) Paste the jar file inside the "endorsed" folder 4) Restart the server and the xerces hell is subsides.

Let me know if the solution worked for you.



来源:https://stackoverflow.com/questions/40388476/classnotfound-xerces-saxparserfactoryimpl-when-running-in-wildfly-8-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!