我正在运行Wildfly 8.2.0并进行一些XML Config文件解析。我的想法是,我将能够使用捆绑的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>
EARContent:
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>
EARContent:
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>
EARContent:
lib/
...(removed xercesImpl.jar)...
META-INF/
application.xml // Information about EJB that uses xercesImpl.jar
jboss-deployment-structure.xml
[4]为JAXP Parser声明Java属性......没有变化
启动Wildfly时:
./standalone.sh -c standalone-full.xml -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
<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>
答案 0 :(得分:0)
尝试变体3,但添加export =&#34; true&#34;依赖 我想你尝试使用ejb或war中的javax.xml.parsers.SAXParserFactory.newInstance()。子部署没有看到耳朵的依赖模块。您必须明确导出。
答案 1 :(得分:0)
问题最终是包含试图加载SAXParserFactoryImpl的EJB的线程的类加载器无法访问它。为了解决这个问题,我必须找到一个具有SAXParserFactoryImpl可见性的类加载器的线程(碰巧在我的MDB上)并在有问题的bean上手动设置它。我从来没有确定发生了什么,但这是一个快速而肮脏的工作。
答案 2 :(得分:0)
经过很多RND终于找到了解决方案。 这是:
1)复制XercesImpl-X.x.x.jar并将其粘贴到/ jre / lib /中 例如: - 对我来说 - &gt; C:\ Program Files \ Java \ jdk1.8.0_131 \ jre \ lib 2)在lib中创建一个新文件夹&#34;认可&#34;。 3)将jar文件粘贴到&#34; 背书&#34;夹 4)重新启动服务器,xerces地狱已经消退。
如果解决方案适合您,请告诉我。