使用其他包导出具有依赖关系的包

时间:2012-01-16 15:11:39

标签: java osgi equinox

我有这个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文件夹中的所有bundle。之后,ConfiguratorModule(一个自定义包)只读取上下文中的所有包,并执行每个包的开始方法(bundleA和bundleB)。我有一个eclipse项目(bundleC),它使用了bundleA和bundleB中定义的一些clases,所以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”选项中有两个bundle,那些项目(BundleA和BundleB)应该在bundleC类路径中,不是吗?因此,在这种情况下,我只生成包(通过将其导出为“插件开发”)并将新包放在插件文件夹中。有什么我想念的吗?

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

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

感谢您的回答

1 个答案:

答案 0 :(得分:0)

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