ClassNotFoundException oracle.i18n.util.LocaleMapper on tomcat TLD scanning. ojdbc7 maven dep (xmlparserv2-12.1.0.2.jar transitive) causes this error

Tags: , , , ,



I am receiving an error when running my spring-boot application with embedded-tomcat (haven’t tried with server tomcat yet).

java.lang.IllegalStateException: Tomcat 7 reflection failed
    at org.springframework.boot.context.embedded.tomcat.SkipPatternJarScanner.scan(SkipPatternJarScanner.java:77)
    at org.apache.catalina.startup.TldConfig.execute(TldConfig.java:271)
    at org.apache.catalina.startup.TldConfig.lifecycleEvent(TldConfig.java:590)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5522)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.context.embedded.tomcat.SkipPatternJarScanner.scan(SkipPatternJarScanner.java:73)
    ... 12 common frames omitted
Caused by: java.lang.NoClassDefFoundError: oracle/i18n/util/LocaleMapper
    at oracle.xml.parser.v2.XMLReader.setEncoding(XMLReader.java:980)
    at oracle.xml.parser.v2.XMLReader.checkXMLDecl(XMLReader.java:3284)
    at oracle.xml.parser.v2.XMLReader.pushXMLReader(XMLReader.java:570)
    at oracle.xml.parser.v2.XMLReader.pushXMLReader(XMLReader.java:274)
    at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:232)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1576)
    at org.apache.catalina.startup.TldConfig.tldScanStream(TldConfig.java:565)
    at org.apache.catalina.startup.TldConfig.tldScanJar(TldConfig.java:513)
    at org.apache.catalina.startup.TldConfig.access$200(TldConfig.java:61)
    at org.apache.catalina.startup.TldConfig$TldJarScannerCallback.scan(TldConfig.java:300)
    at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:259)
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:221)
    ... 17 common frames omitted
Caused by: java.lang.ClassNotFoundException: oracle.i18n.util.LocaleMapper
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 29 common frames omitted

On further inspection, It appears as though the previous version of the orai18n.jar depended on by the ojdbc7 maven dep contained this class in vesion 11.2.0.3 but the newer (12.1.0.2) file does not contain it.

Answer

It’s a conflict with xmlparserv2. Try this :

    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.2</version>
        <exclusions>
            <exclusion>
                    <groupId>com.oracle.jdbc</groupId>
                    <artifactId>xmlparserv2</artifactId>
            </exclusion>
        </exclusions>
    </dependency>


Source: stackoverflow