XercesImpl in conflict with JavaSE 6's internal xerces implementation. Both are needed… what can be done?

五迷三道 提交于 2019-11-29 01:56:41

As per http://xml.apache.org/xalan-j/faq.html#faq-N100EF

To use a newer version of Xalan-Java and override the one packaged with the JDK:

use the Endorsed Standards Override Mechanism. Place the xalan.jar, serializer.jar, xercesImpl.jar and xml-apis.jar in the \lib\endorsed directory of the JRE, where is where the runtime software is installed

Gabriel

Instead of using:

// Uses first classloader-available implementation found:
//import javax.xml.validation.SchemaFactory;
SchemaFactory schemaFactory= SchemaFactory.newInstance(
    XMLConstants.W3C_XML_SCHEMA_NS_URI);

Try using (Since Java 1.6):

// Uses org.apache.xerces.jaxp.validation.XMLSchemaFactory subclass 
//of SchemaFactory as implementation:
//import javax.xml.validation.SchemaFactory;
SchemaFactory schemaFactory= SchemaFactory.newInstance(
    XMLConstants.W3C_XML_SCHEMA_NS_URI,
    "org.apache.xerces.jaxp.validation.XMLSchemaFactory",
    null);

See the related JavaDoc.

Or use META-INF/services engineering: article with examples

Hope it still helps somebody.

Gabriel

The first thing to try is to put the xerces jar in the endorsed directory. That will cause the whole JVM to use Xerces consistently. That may solve the whole problem right there, unless there is something special about 2.8.1 I don't know about.

Vadzim

Note that it's possible to endorse libs without modifying jre by setting java.endorsed.dirs system property.

See what is the exact way to use Endorsed directory in jdk1.6.

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