Why JAXB does not work in a bundle?

2,400 views
Skip to first unread message

Coskun Tasoluk

unread,
Apr 18, 2014, 11:51:54 PM4/18/14
to bndtool...@googlegroups.com
Hi,

I am trying to use EclipseLink MOXy  for marshalling/unmarshalling XML. However, I have been getting ClassNotFoundException as you see below.

javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]

It fails, when it is creating new JAXBContext instance. Here is the code segment:

        @Activate
void activate(Map<String,Object> properties) {
try {
                        jaxbContext = JAXBContext.newInstance(com.aahaber.newsml.model.NewsML.class);
//ClassLoader cl = com.aahaber.newsml.model.ObjectFactory.class.getClassLoader();
//jaxbContext = JAXBContext.newInstance(com.aahaber.newsml.model.NewsML.class, com.aahaber.newsml.model.ObjectFactory.class);
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
//jaxbContext = JAXBContext.newInstance("com.aahaber.newsml.model", cl);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

I have tried many things, but I can not get it run. 
Yes, I have jaxb.index in com.aahaber.newsml.model package
I have jaxb.properties in the package as well:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

I am out of ideas to try, please let me know if you have one. Here is full error stack trace

javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:186)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:330)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:618)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:565)
at com.aahaber.newsml.NewsMLParserImpl.activate(NewsMLParserImpl.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:236)
at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:37)
at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:613)
at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:496)
at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:149)
at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createImplementationObject(ImmediateComponentManager.java:239)
at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createComponent(ImmediateComponentManager.java:119)
at org.apache.felix.scr.impl.manager.AbstractComponentManager$Registered.getService(AbstractComponentManager.java:1694)
at org.apache.felix.scr.impl.manager.ImmediateComponentManager.getService(ImmediateComponentManager.java:667)
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:308)
at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:219)
at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:320)
at org.apache.felix.framework.Felix.getService(Felix.java:3568)
at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:468)
at com.aahaber.app.Application.start(Application.java:50)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at aQute.launcher.Launcher.update(Launcher.java:378)
at aQute.launcher.Launcher.activate(Launcher.java:303)
at aQute.launcher.Launcher.run(Launcher.java:193)
at aQute.launcher.Launcher.main(Launcher.java:89)
Caused by: java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:480)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:184)
... 31 more

Thank you,
Coskun


Rafał Krzewski

unread,
Apr 19, 2014, 6:02:45 PM4/19/14
to bndtool...@googlegroups.com
Apparently, org.eclipse.persistence.jaxb package is not on your bundle classpath. How does your manifest look like?
I don't know much about JAXB, but there might be deeper issues here as well, looking at the code - thread context class loaders and OSGi don't mix well.
Cheers,
Rafał

Coskun Tasoluk

unread,
Apr 19, 2014, 9:15:19 PM4/19/14
to bndtool...@googlegroups.com
Hi Rafal,

Thank you for the reply. I think, the problem is EclipseLink MOXy. I can get JAXB working with the JRE distribution. I could not figure out why it did not work with EclipseLink MOXy. I tried whatever I found on the Internet, nothing seems to work. 

Thank you,
Coskun 

Dave

unread,
Jun 10, 2014, 3:14:55 PM6/10/14
to bndtool...@googlegroups.com
It could be how MOXy loads the class if it bypasses what OSGi is trying to do.

What bundle contains the class that cannot be found and what bundle contains the code that is trying to create the context? If in separate bundles, is the context class package exported?
Reply all
Reply to author
Forward
0 new messages