【问题标题】:OSGI: Using code in another bundle from a fragmentOSGI:使用片段中另一个包中的代码
【发布时间】:2018-02-12 18:45:35
【问题描述】:

我想将一个 OSGI 片段添加到一个包中,这里是“org.eclipse.equinox.http.jetty”,带有这样的 Manifest.mf:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JettyCustomize
Bundle-SymbolicName: com.company.st.console.jetty.customize
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Company
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Fragment-Host: org.eclipse.equinox.http.jetty

不幸的是,我的代码需要在“org.eclipse.jetty.io”中定义的其他包中的代码。所以我将以下行添加到清单中:

Import-Package: org.eclipse.jetty.io

现在 - 在 Eclipse 中 - 代码编译。但是当我启动应用程序时,我得到以下异常(MyJettyCustomizer 是片段中的一个类,由片段主机“org.eclipse.equinox.http.jetty”中的代码每次反射使用):

java.lang.ClassNotFoundException: com.company.st.console.jetty.customize.MyJettyCustomizer cannot be found by org.eclipse.equinox.http.jetty_3.4.0.v20170503-2025
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.eclipse.equinox.http.jetty.internal.HttpServerManager.createJettyCustomizer(HttpServerManager.java:232)
    at org.eclipse.equinox.http.jetty.internal.HttpServerManager.updated(HttpServerManager.java:74)
    at org.eclipse.equinox.http.jetty.internal.Activator.start(Activator.java:62)
    at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:779)
    at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:772)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:729)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:933)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:309)
    at org.eclipse.osgi.container.Module.doStart(Module.java:581)
    at org.eclipse.osgi.container.Module.start(Module.java:449)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1628)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1608)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1579)
    at org.eclipse.osgi.container.SystemModule.startWorker(SystemModule.java:264)
    at org.eclipse.osgi.container.Module.doStart(Module.java:581)
    at org.eclipse.osgi.container.Module.start(Module.java:449)
    at org.eclipse.osgi.container.SystemModule.start(SystemModule.java:188)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:402)
    at org.eclipse.osgi.launch.Equinox.start(Equinox.java:115)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:326)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:239)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1472)

如果我从MyJettyCustomizer 中删除需要“org.eclipse.jetty.io”的代码并再次从清单中删除“Import-Package: org.eclipse.jetty.io”行,则不会出现异常运行时和类MyJettyCustomizer 已正确加载。

那么有没有可能我可以在 OSGI 片段中使用来自另一个包的代码?

【问题讨论】:

    标签: java eclipse osgi osgi-fragment


    【解决方案1】:

    您是否碰巧在多个捆绑包/片段中包含com.company.st.console.jetty.customize 包?好像是分包问题!

    【讨论】:

      猜你喜欢
      • 2011-10-31
      • 2013-01-04
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多