20060824 Thursday August 24, 2006

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

Posted by rickg ( Aug 24 2006, 09:45:46 PM PDT ) Permalink Comments [14]
Comments:

It's great that you decided to share this, because I just ran into exactly the same problem today.

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 #

This was awesome. I would have never thought of that conflict. It also rears its head when running a JBoss server. I was able to rename those files temporarily in my C:\jboss-4.0.3\lib\endorsed directory and my Solr config files were finally discovered. Now I just need to fix my config files ;-)

Posted by Dirck Hecking (64.127.105.250) on July 23, 2007 at 12:00 AM PDT #

Glad I could help!

Posted by Psuedo Guru (121.116.150.99) on August 14, 2007 at 09:41 AM PDT #

Oh, thanks so much! I had the same trouble when trying to deploy Sesame2 under Tomcat5.5. Removing those files from $TOMCAT_HOME/common/endorsed/ did the trick. At least the Web interface is not showing up.

Knud

Posted by Knud Hinnerk Möller (140.203.154.12) on October 08, 2007 at 06:28 PM PDT
Website: http://kantenwerk.org #

Another thanks! same problem and removing those files did the trick!

Posted by 80.91.33.37 on October 30, 2007 at 04:35 PM PDT #

works for me, thanks!

Posted by wei (135.207.24.87) on March 08, 2008 at 04:47 AM PST #

Is there any tool available to figure out conflicting classes?

Posted by bangalorean (57.73.18.106) on April 20, 2008 at 02:29 PM PDT
Website: http://jobs.co.in #

Wei: no tool that I am aware of. Other people might have some ideas.

Posted by Psuedo Guru (24.16.187.228) on May 03, 2008 at 05:27 AM PDT #

Yet another thanks!

Posted by rob smith (207.14.29.3) on September 02, 2008 at 03:22 AM PDT #

Saved me much time. Thank you!

Posted by jerome (206.12.30.42) on November 25, 2008 at 08:04 PM PST
Website: http://maestric.com #

Thanks so much !
It saved a lot of time.

Posted by SM (207.67.73.194) on January 04, 2009 at 10:18 PM PST #

Ah, so nice I found your post, these kind of error's makes one crazy normally, but your steps resolved the issue in 2 mins. Thanks

Posted by taknev (121.245.22.253) on April 14, 2009 at 10:20 AM PDT #

THANK YOU!

Posted by Alexandre Almeida (200.222.1.254) on July 09, 2009 at 11:15 AM PDT #

Thanks!! you just saved me quite a hassle :)

Posted by Jeroen (92.66.234.97) on May 12, 2010 at 05:59 AM PDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed