Failed to create an XPathFactory for the default object model
Got the following error today after uploading a web app that used the Java XPath API to my server.
java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom
javax.xml.xpath.XPathFactory.newInstance(Unknown Source)
com.alschulerassociates.phrdemo.cda.CDADocXpathImpl.<init>(CDADocXpathImpl.java:18)
com.alschulerassociates.phrdemo.cda.CDALoader.loadCDA(CDALoader.java:30)
com.alschulerassociates.phrdemo.cda.CDALoader.loadCDA(CDALoader.java:26)
I looked through the source for XPathFactory and found this interesting comment:
/**
* <p>Get a new <code>XPathFactory</code> instance using the default object model,
* {@link #DEFAULT_OBJECT_MODEL_URI},
* the W3C DOM.</p>
*
* <p>This method is functionally equivalent to:</p>
* <pre>
* newInstance(DEFAULT_OBJECT_MODEL_URI)
* </pre>
*
* <p>Since the implementation for the W3C DOM is always available, this method will never fail.</p>
*
* @return Instance of an <code>XPathFactory</code>.
*/
public static final XPathFactory newInstance() {
try {
return newInstance(DEFAULT_OBJECT_MODEL_URI);
} catch (XPathFactoryConfigurationException xpathFactoryConfigurationException) {
throw new RuntimeException(
"XPathFactory#newInstance() failed to create an XPathFactory for the default object model: "
+ DEFAULT_OBJECT_MODEL_URI
+ " with the XPathFactoryConfigurationException: "
+ xpathFactoryConfigurationException.toString());
}
}
I like the "this method will never fail" part.
Finally found out that the problem was due to the Tomcat Java 1.4 compatibility libraries. I had recently upgraded to Java 1.5, but forgot to remove them.
$TOMCAT_HOME/common/endorsed/xercesImpl.jar
$TOMCAT_HOME/common/endorsed/xml-apis.jar

