【问题标题】:Exporting a bundle with dependencies with another bundles导出具有依赖关系的包与另一个包
【发布时间】:2012-01-16 15:11:38
【问题描述】:

我有这个 OSGI 配置:

/configurations
   config.ini
   somebundle.properties
/plugins
   bundleA
   bundleB
osgi-3.4.2-R34x_v2008826-1230.jar
org.eclipse.equinox.common_3.4.0.v20080421-2006.jar
org.eclipse.update.configurator_3.2.201.R34x_v20080819.jar
com.test.arquitectura.osgi.ConfiguratorModule_1.0.0.jar

我的 config.ini 是这样的:

osgi.bundles=org.eclipse.equinox.common@2:start, \
    org.eclipse.update.configurator@3:start, \
    com.test.arquitectura.osgi.ConfiguratorModule_1.0.0.jar@3:start
osgi.clean = true
eclipse.ignoreApp=true
osgi.parentClassLoader=app

所以,AFAIK,当我执行时

java -Xms256M -Xmx1280M -jar osgi-3.4.2-R34x_v20080826-1230.jar 

它读取 config.ini,因此使用 equinox.common 和 update.configurator 捆绑它“检测”部署在 /plugins 文件夹中的所有捆绑包。之后,ConfiguratorModule(自定义包)只是读取上下文中的所有包并执行每个包(bundleA 和 bundleB)的 start 方法。我有一个eclipse项目(bundleC),它使用了bundleA和bundleB中定义的一些类,所以MANIFEST.MF是:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: BundleC Plug-in
Bundle-SymbolicName: com.test.bundlec
Bundle-Version: 1.0.0
Bundle-Activator: com.test.bundlec.Activator
Import-Package: javax.naming,javax.sql,org.osgi.framework;version="1.3
 .0",org.osgi.util.tracker;version="1.3.1"
Bundle-ClassPath: .
Require-Bundle: com.test.BundleA;bundle-version="1.0.0",
com.test.BundleB;bundle-version="1.0.0"

所以,我想为 bundleC 项目生成一个插件(jar)文件。由于“Require-bundle”选项中有两个包,这些项目(BundleA 和 BundleB)应该在 bundleC 类路径中,不是吗?因此,在这种情况下,我只生成包(通过将其导出为“插件开发”)并将新包放在插件文件夹中。我有什么遗漏吗?

好吧,如果我所说的都是正确的,这就是我的问题。我有 BundleA 和 BundleB 的插件 jar 文件,但我没有它们的源代码,所以在将 BundleC 导出到 jar 插件时出现错误,因为很明显,它找不到所需的类从 BundleA 和 BundleB 使用。有没有办法在类路径中没有那些必需的捆绑包来生成插件?

我尝试“反编译”它们,然后创建项目,并将它们添加到 BundleC 的类路径中。我可以生成插件,然后将它放在插件文件夹中,但是在执行osgi环境时,找不到bundleC。我做错了什么?

感谢您的回答

【问题讨论】:

  • 请发布您得到的确切错误,任何堆栈跟踪等

标签: java osgi equinox


【解决方案1】:

为了使用 BundleA 和 BundleB 中的某些内容,他们需要导出它(例如,他们可以导出一个类以供其他包使用)。然后在 BundleC 中,您需要等到 BundleA 和 BundleB 被加载(例如使用 BundleListener 的实现,尽管这种情况通常使用服务和 ServiceTracker)。

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多