Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPathFactoryImpl not found error (using myBatis)

Using myBatis standAlone (Atlassian jira plugin(OSGi) environmnent)

The following error has occurred.

[INFO] [talledLocalContainer] org.apache.ibatis.exceptions.PersistenceException:
[INFO] [talledLocalContainer]     ### Error building SqlSession.
[INFO] [talledLocalContainer]     ### Cause: java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default o
bject model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.
util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: Provider org.apache.xpath.jaxp.XPathFactoryImpl not found
[INFO] [talledLocalContainer] ### Cause: 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: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: Provider org.apache.xpath.jaxp.XPathFactoryImpl not found

Source Code

static {
    try {
        // set SessionFactory
        if (MyBatisConnectionFactory.sqlSessionFactory == null) {
            MyBatisConnectionFactory.sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("/mybatisConfig.xml"));
        }

    } catch (final Exception e) {
        MyBatisConnectionFactory.LOGGER.error(e.getMessage());
    } finally {
    }
}

When adding xalan, the following error occurs.

Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory

This error did not occur in Pure Java Application environment.

I wonder why this error occurs.

Please help me.

Thanks.

like image 518
Jongbum Lee Avatar asked Dec 04 '16 03:12

Jongbum Lee


1 Answers

I got similar errors and this awkward looking thing, documented here, fixed it for me:

-Djavax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom=com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl

I'm using this java version on macos:

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

The stderr from -Djaxp.debug=1 helped me find this:

JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom'
JAXP: The property is undefined.

So I gave it exactly what it was asking for and it got all happy and such:

JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom'
JAXP: The value is 'com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl'
JAXP: createInstance(com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl)
JAXP: loaded com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl from jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Hom     e/jre/lib/rt.jar!/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.class
JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl' was found for http://java.sun.com/jaxp/xpath/dom

I am curious about the :uri syntax, because the following work just fine without :uri. So why does XPath require this and these others don't?

-Dcom.sun.org.apache.xml.internal.dtm.DTMManager=com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
like image 174
Erik Ostermueller Avatar answered Sep 27 '22 23:09

Erik Ostermueller