Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXBContextFactory hell - java.lang.ClassNotFoundException: com.ibm.xml.xlxp2.jaxb.JAXBContextFactory

Tags:

java

xml

jaxb

I keep getting the following error in my dev environment. I use

  • Eclipse Mars 4.5.1
  • Oracle JDK 1.7 (build 1.7.0_79-b15) or 1.8 (build 1.8.0_65-b17)
  • Apache Ant to run the code as well as Eclipse to run the code
  • Ivy for dependency management where I include the following

    <!-- 3rd party dependencies -->
    <dependency org="log4j" name="log4j" rev="1.2.16" conf="test->default"/>
    <dependency org="commons-httpclient" name="commons-httpclient" rev="3.1" conf="compile->default"/>
    <dependency org="org.jvnet.jaxb2_commons" name="jaxb2-basics-runtime" rev="0.6.4" conf="default->runtime"/>
    <dependency org="org.jvnet.jaxb2_commons" name="jaxb2-basics-tools" rev="0.6.4" conf="default->runtime"/>
    <dependency org="org.jvnet.jaxb2_commons" name="jaxb2-basics" rev="0.6.4" conf="default->runtime"/>
    

I've seen the other posts on this topic but their answers don't help much. I tried using a jaxb.properties but that did not change the behavior.

javax.xml.bind.context.factory=com.sun.tools.xjc.runtime.JAXBContextFactory


Exception in thread "main" javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.ibm.xml.xlxp2.jaxb.JAXBContextFactory]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:227)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:432)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:637)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584)
    at com.acme.merge.util.ProjectsInformation.unMarshal(ProjectsInformation.java:24)
    at com.acme.merge.controller.MergeController.main(MergeController.java:44)
Caused by: java.lang.ClassNotFoundException: com.ibm.xml.xlxp2.jaxb.JAXBContextFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:563)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:225)
    ... 5 more

What am I overlooking?

like image 559
David Brossard Avatar asked Oct 23 '25 12:10

David Brossard


2 Answers

I found the root cause. Some of my dependencies in ivy have transitive dependencies that bring in some IBM WS libraries. These libraries override my settings and force the use of com.ibm.xml.xlxp2.jaxb.JAXBContextFactory. Excluding these resolved my issue.

The conflicting jar is from package com.ibm.ws and is called runtime.jar.

like image 158
David Brossard Avatar answered Oct 25 '25 01:10

David Brossard


The solution that seem to work for me :

https://java.wekeepcoding.com/article/19606872/Issue+in+creating+an+instance+of+JAX-WS+client+to+access+the+service

The Missing class "com.ibm.xml.xlxp2.jaxb.JAXBContextFactory" is available in the jar "com.ibm.jaxws.thinclient_8.5.0.jar" which will be available in the server runtime directory for Websphere App server : C:\Program Files\IBM\WebSphere\AppServer\runtimes. Please include this jar for compile purpose only and donot include this in your WAR or EAR as it will conflict with your server runtime library jar. For server WAS 8.0 the path jar would be "com.ibm.jaxws.thinclient_8.0.0.jar".

like image 38
Gouri Yashodhan Avatar answered Oct 25 '25 02:10

Gouri Yashodhan