1

我正在运行一个非常简单的 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

javax.xml 不是随 java 1.6 一起提供的吗?我也尝试添加 javax.xml 包,但这并没有解决问题。

4

2 回答 2

4

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

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

于 2013-01-18T15:51:49.053 回答
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);
        }
    });         
}

希望能帮助到你

于 2014-07-25T16:00:53.950 回答