获取和使用Equinox OSGi 实现
Equinox OSGi 框架的实现组成了EclipseRCP和IDE平台的支柱,实际上,它是一个完整独立的OSGi实现。 要运行 Equinox OSGi ,下载 org.eclipse.osgi JAR 或者在你的Eclise安装目录下找 <install location>/eclipse/plugins/org.eclipse.osgi_3.2.0_xxx.jar。一旦你有 Equinox 框架的 JAr,使用下面的命令行:
jar -jar org.eclipse.osgi_3.2.0.jar -console
一旦运行,你会看到提示符 osgi> ,这是等待你输入命令的OSGi控制台。输入 “?”,可以得到命令帮助提示。开始时,最感兴趣的命令是:
• install <bundle URL> – 安装指定URL的bundle
• start <bundle # or bundle name> – 使用指定的序号或者符号ID启动 bundle
• stop <bundle # or bundle name> – 使用指定的序号或者符号ID停止 bundle
• ss – 报告所有已安装的bundle的摘要状态
• diag <bundle # or bundle name> – 使用指定的序号或者符号ID,报告bundle的resolution问题
配置和所有相关的
Equinox OSGi 实现是非常用配置的。一个最通用的配置方式是,让框架自动启动,然后安装和启动一组bundles。当你运行Eclipse IDE的时候,过程就是这样的。 这里说明它是怎么运行,你如何使用的问题。
加入你有B1.jar 和 B2.jar 两个bundles,你想在Equinox运行时安装和启动这两个bundles。 就是使用其他OSGi实现,你也可以通过控制台安装和运行B1.jar 和 B2.jar。这是个手动的过程,但是你只需要做一次(OSGi框架会记住已安装和启动的bundle)。要自动完成这些事情,穿件一个configuration,这里面列出要被安装和启动的B1.jar和B2.jar。设置如下:
somedir/
configuration/
config.ini
org.eclipse.osgi_3.2.0.jar
B1.jar
B2.jar
上面的 config.ini 是一个Java属性文件,包含下面的行。注意osgi.bundles属性功能非常强大。具体参考文档。
osgi.bundles=B1.jar@start, B2.jar@start
eclipse.ignoreApp=true
当Equinox使用上面的命令行启动时,B1和B2将被安装和启动。如果你想指定另一个configuration,仅需要增加 -configuration <location> 到命令行。主要,由于这里你只是运行你自己的bundles,我们增加一行内容来告诉Equinox,让它跳过试图启动一个Eclipse应用这一步。这个设置不是必须的,没有的话,你的log里面会有一些无关的信息。关于命令行参数和系统属性的设置,请参考:
http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.isv/reference/misc/index.html
http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html
现在,要想把事情变的更容易,你可以增加一些 Eclipse bundles(例如, org.eclipse.equinox.common 和 org.eclipse.update.configurator)。这能提供自动发现/安装bundle的能力。设置如下:
somedir/
configuration/
config.ini
org.eclipse.osgi_3.3.0.jar
org.eclipse.equinox.common_3.3.0.jar
org.eclipse.update.configurator_3.2.100.jar
plugins/
B1.jar
B2.jar
在你的config.ini文件中增加这些 bundles:
osgi.bundles=org.eclipse.equinox.comment@2:start, org.eclipse.update.configurator@3:start
当 Update configurator bundle启动,它自动发现和安装 plugin 目录中处理 Equinox JAR外 所有的bundles。注意,configurator不会自动启动这些bundles。
最后,如果你使用3.3版,你可以增加 equinox launcher 到 configuration中。equinox launcher 又3块组成:本地executable(eclipse.exe),一个共享库(eclipse_1017.dll)和一个launcher jar (org.eclipse.equinox.launcher_1.0.0.jar)。executable 在 eclipse install 的根目录。共享库是特定的平台碎片(例如,org.eclipse.equinox.launcher.win32.win32.x86)。共享库和 launcher jar 位于 plugins 目录中。配置详情如下:
somedir/
configuration/
config.ini
eclipse.exe
plugins/
org.eclipse.equinox.common_3.3.0.jar
org.eclipse.equinox.launcher.win32.win32.x86_1.0.0/
eclipse_1017a.dll
[other launcher fragment content]
org.eclipse.equinox.launcher_1.0.0.jar
org.eclipse.osgi_3.3.0.jar
org.eclipse.update.configurator_3.2.100.jar
B1.jar
B2.jar
当 equinox launcher 使用时,所有的 bundles (包括框架 org.eclipse.osgi )都要放在 plugins目录下。equinox launcher 的缺省配置是用来启动 eclipse 应用的。如果eclipse应用没有被找到,那么OSGi框架将关闭然后equinox退出。为了防止这种情况,config.ini 里面必须配置另一个属性(osgi.noShutdown=truen)。那么最终的config.ini如下所示:
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start
eclipse.ignoreApp=true
osgi.noShutdown=true
一旦设置完毕,你可以使用下面的命令通过控制台启动equinox:
eclipse -console
Eclipse和Equinox提供一组中药的扩展和配置选项(例如,extension registry, application model, shared installs,…),这超过了作为一个Getting Started文档的范围。要使用eclipse的全部能力,看Eclipse IDE和RCP应用是如何架构和check out帮助系统的链接:
http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.isv/reference/misc/multi_user_installs.html
那些对OSGi的Eclipse扩展比较感兴趣的,请看:
http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.isv/reference/misc/bundle_manifest.html
大多数工具是实现性质的。很普遍的概念已经被提交在OSGi R4.1 或者 R5 规范,其他的到Eclipse规范。所有的东西都到位,来解决实质问题,我们(或者我们的顾客)都有。你可能也有一些相关的问题。