导出与其他包有依赖关系的包
我有这个 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
所以,据我所知,当我执行
java -Xms256M -Xmx1280M -jar osgi-3.4.2-R34x_v20080826-1230.jar
它时,它会读取 config.ini,因此与 equinox.common 和 update.configurator 捆绑在一起,它“检测”部署在 /plugins 文件夹中的所有捆绑包。之后,ConfiguratorModule(自定义捆绑包)仅读取上下文中的所有捆绑包并执行每个捆绑包(捆绑包 A 和捆绑包 B)的 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 的类路径中。我可以生成插件,然后将其放在plugins文件夹中,但是当执行osgi环境时,找不到bundleC。我做错了什么?
感谢您的回答
I have this OSGI configuration:
/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
My config.ini is like this:
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
So, AFAIK, when I execute
java -Xms256M -Xmx1280M -jar osgi-3.4.2-R34x_v20080826-1230.jar
It reads config.ini so with equinox.common and update.configurator bundles it "detects" all bundles deployed in /plugins folder. After that, the ConfiguratorModule (a custom bundle) just reads all bundles in the context and executes start method of each one (bundleA and bundleB). I have an eclipse project (bundleC), which uses some clases defined in bundleA and bundleB, so the MANIFEST.MF is:
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"
So, I want to generate a plugin (jar) file for the bundleC project. As there are two bundles in the "Require-bundle" option, those projects (BundleA and BundleB) should be in the bundleC classpath, isn´t it? So, in that case, I just generate the bundle (by exporting it as "Plugin Development") and place the new bundle in the plugin folder. Is there something I'm missing?
Well, in case all I´ve said is correct, here is my problem. I have the plugin jar file for BundleA and BundleB but I don´t have the source code of them, so I get an error when exporting BundleC to a jar plugin because, as it seem obvious, it can´t find the required classes it uses from BundleA and BundleB. Is there any way to generate the plugin without those required-bundles in the classpath?
I´ve tried to "decompile" them and then create the projects, and adding them in the classpath of BundleC. I can generate the plugin, then I place it in the plugins folder, but when execute the osgi enviroment, the bundleC is not found. What I´m doing wrong?
Thanks for your answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使用 BundleA 和 BundleB 中的某些内容,他们需要导出它(例如,他们可以导出一个类以供其他包使用)。然后在 BundleC 中,您需要等待 BundleA 和 BundleB 加载(例如,使用 BundleListener 的实现,尽管这种情况通常是使用服务和 ServiceTracker 实现的)。
In order to use something from BundleA and BundleB, they need to export it ( for example they can export a class for usage by other bundles). Then in BundleC you need to wait until BundleA and BundleB are loaded (for example with implementation of BundleListener, though this scenario is usually made with services and ServiceTracker).