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


I also got a kick out of the "this method will never fail" part of the Javadoc. But if it wasn't for your post, I'm afraid it would take ages for me to figure it out.
Thanks once again!
Posted by Jakub Wasilewski (212.182.117.171) on June 20, 2007 at 11:42 AM PDT #
Posted by Dirck Hecking (64.127.105.250) on July 23, 2007 at 12:00 AM PDT #
Posted by Psuedo Guru (121.116.150.99) on August 14, 2007 at 09:41 AM PDT #
Knud
Posted by Knud Hinnerk Möller (140.203.154.12) on October 08, 2007 at 06:28 PM PDT
Website: http://kantenwerk.org #
Posted by 80.91.33.37 on October 30, 2007 at 04:35 PM PDT #
Posted by wei (135.207.24.87) on March 08, 2008 at 04:47 AM PST #
Posted by bangalorean (57.73.18.106) on April 20, 2008 at 02:29 PM PDT
Website: http://jobs.co.in #
Posted by Psuedo Guru (24.16.187.228) on May 03, 2008 at 05:27 AM PDT #
Posted by rob smith (207.14.29.3) on September 02, 2008 at 03:22 AM PDT #
Posted by jerome (206.12.30.42) on November 25, 2008 at 08:04 PM PST
Website: http://maestric.com #
It saved a lot of time.
Posted by SM (207.67.73.194) on January 04, 2009 at 10:18 PM PST #
Posted by taknev (121.245.22.253) on April 14, 2009 at 10:20 AM PDT #
Posted by Alexandre Almeida (200.222.1.254) on July 09, 2009 at 11:15 AM PDT #
Posted by Jeroen (92.66.234.97) on May 12, 2010 at 05:59 AM PDT #