Equinox java.lang.NoClassDefFoundError

时间:2013-01-18 15:37:43

标签: java jaxb osgi equinox

我正在运行一个非常简单的osgi包,其激活器看起来像这样

 public void start(BundleContext bundleContext) throws Exception {
    JAXBContext con =  JAXBContext.newInstance(Activator.class);
 }

这总是抛出异常

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

我正在运行java版本" 1.6.0_37"。这些是我正在运行的捆绑包

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

java 1.6附带的javax.xml是不是?我也尝试过添加javax.xml包,但这并没有解决问题。

2 个答案:

答案 0 :(得分:4)

您需要确保在javax.xml.bind文件中导入META-INF/MANIFEST.MF包或JAXB公共API包。

OSGi示例(MOXy用作JAXB(JSR-222)提供程序)

答案 1 :(得分:0)

我有类似的问题并设法使用AccessController.doPrivileged解决它:

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);
        }
    });         
}

希望有所帮助