0

I have a web application on tomcat. The application needs two SAXParserFactory implements: one is JDK default implement com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl, the other one is from xerces: org.apache.xerces.jaxp.SAXParserFactoryImpl.

Here's the problem, SAXParserFactory.newInstance() just selects only one implementation by specific order, as follows:

  • Use the javax.xml.parsers.SAXParserFactory system property.
  • UseUse the JAVA_HOME(the parent directory where jdk is installed)/lib/jaxp.properties for a property file that contains the name of the implementation class keyed on the same value as the system property defined above.
  • Use the Services API (as detailed in teh JAR specification), if available, to determine the classname. The Services API will look for a classname in the file META-INF/services/javax.xml.parsers.SAXParserFactory in jars available to the runtime.
  • Platform default SAXParserFactory instance.

I tried to configure the different classnames in javax.xml.parsers.SAXParserFactory in different jar files. But it's scope for whole classloader. In tomcat, all application libs are loaded in one classloader. For instance, the configure file in A.jar will overwrite the configure in B.jar, eventually all application gets the configure from A.jar.

So my question is how can I specific these two SAXParserFactory implementations in one web application? Thank you.

卢声远 Shengyuan Lu
  • 31,208
  • 22
  • 85
  • 130
  • Can you not get one implementation, then set the `javax.xml.parsers.SAXParserFactory` system property and then get the other implementation? – Matti Lyra Aug 27 '12 at 15:45

2 Answers2

0

Pretty sure you can't (unless you use multiple classloaders). The code which depends on the other implementation should instantiate it directly (using the implementation class name).

jtahlborn
  • 52,909
  • 5
  • 76
  • 118
-1

The implementation to use can also be defined via

-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl

as java command line argument.

Strinder
  • 2,111
  • 2
  • 21
  • 34