问题
I am running a very simple osgi bundle whose activator looks like this
public void start(BundleContext bundleContext) throws Exception {
JAXBContext con = JAXBContext.newInstance(Activator.class);
}
This always throws exception
org.osgi.framework.BundleException: Exception in com.test.bundle.Activator.start() of bundle com.test.bundle.
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext
at com.test.bundle.Activator.start(Activator.java:26)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
... 12 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBContext
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 16 more
I am running java version "1.6.0_37". These are the bundles i am running
id State Bundle
0 ACTIVE org.eclipse.osgi_3.8.0.v20120529-1548
1 ACTIVE org.eclipse.core.runtime_3.8.0.v20120521-2346
2 ACTIVE org.ops4j.pax.logging.pax-logging-api_1.7.0
3 RESOLVED com.test.bundle_1.0.0.201301181429
4 ACTIVE org.eclipse.equinox.common_3.6.100.v20120522-1841
5 ACTIVE org.eclipse.equinox.console_1.0.0.v20120522-1841
6 ACTIVE org.apache.felix.gogo.runtime_0.8.0.v201108120515
7 ACTIVE org.apache.felix.gogo.shell_0.8.0.v201110170705
8 ACTIVE org.apache.felix.gogo.command_0.8.0.v201108120515
9 ACTIVE org.eclipse.core.jobs_3.5.300.v20120622-204750
10 ACTIVE org.eclipse.equinox.registry_3.5.200.v20120522-1841
11 ACTIVE org.eclipse.equinox.preferences_3.5.0.v20120522-1841
12 ACTIVE org.eclipse.core.contenttype_3.4.200.v20120523-2004
13 ACTIVE org.eclipse.equinox.app_1.3.100.v20120522-1841
isn't javax.xml shipped with java 1.6 ? I also tried adding javax.xml bundles but that didn't solve the issue.
回答1:
You will need to be sure that you import the javax.xml.bind
package or the JAXB public API bundle in the META-INF/MANIFEST.MF
file.
OSGi Example (MOXy used as JAXB (JSR-222) provider)
- Moxy error with Karaf
回答2:
I had a similar problem and managed to solve it using AccessController.doPrivileged like this:
public void start(BundleContext bundleContext) throws Exception {
JAXBContext con = AccessController.doPrivileged(new PrivilegedExceptionAction<JAXBContext>() {
public JAXBContext run() throws JAXBException {
// needs to run here otherwise throws AccessControlException
return JAXBContext.newInstance(Activator.class);
}
});
}
Hope it helps
来源:https://stackoverflow.com/questions/14402287/equinox-java-lang-noclassdeffounderror