osgiosgi入门


备注

OSGi是JVM的动态模块系统规范。它具有不同版本和受众的规范。还有多种实现方式:

版本3中的Eclipse基于OSGi。从6.9开始, NetBeans也能够处理OSGi模块。 Liferay门户网站自版本7以来也开始使用OSGi作为其模块化基础。

版本

发布日期
SGR1 2000-05-01
SPR2 2001-10-01
SR3 2003-03-01
SR4 2005-11-01
SR4.1 2007-05-01
SR4.2核心 2009-09-01
SR4.2竞争力 2009-09-01
SR4.2企业版 2010-03-01
SR4.3核心 2011-04-01
SR4.3竞争力 2012-05-01
SR4.3住宅 2012-05-01
SR5核心 2012-06-01
SR5企业版 2012-06-01
SR6核心 2014-06-01
SR6汇编 2014-06-01
SR6企业版 2015年8月1日
SR6 Residental 2015年8月1日

注意: https//www.osgi.org/developer/specifications/未提及确切日期,因此在表格中使用该月的第一天。

下载和使用Equinox

Equinox下载页面下载并提取适用于您平台的OSGi入门套件,以获取Neon版本

使用以下命令从rt/plugins folder 启动框架(或从rt 文件夹中获取平台的rt 可执行文件):

rt/plugins$ java -jar org.eclipse.equinox.launcher_1.3.200.v20160318-1642.jar -console
osgi>
 

在OSGi控制台提示符中,您可以管理包,例如:

osgi>ss
"Framework is launched."

id      State       Bundle
0       ACTIVE      org.eclipse.osgi_3.11.0.v20160603-1336
                    Fragments=1
1       RESOLVED    org.eclipse.osgi.compatibility.state_1.0.200.v20160504-1419
                    Master=0
2       RESOLVED    org.apache.commons.codec_1.6.0.v201305230611
3       RESOLVED    org.apache.commons.logging_1.1.1.v201101211721
4       ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215
5       ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036
6       ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605
7       RESOLVED    org.apache.httpcomponents.httpclient_4.3.6.v201511171540
8       RESOLVED    org.apache.httpcomponents.httpcore_4.3.3.v201411290715
9       STARTING    org.eclipse.core.jobs_3.8.0.v20160509-0411
10      STARTING    org.eclipse.ecf_3.8.0.v20160405-1820
                    Fragments=17
11      STARTING    org.eclipse.ecf.filetransfer_5.0.0.v20160405-1820
12      STARTING    org.eclipse.ecf.identity_3.7.0.v20160405-1820
13      STARTING    org.eclipse.ecf.provider.filetransfer_3.2.200.v20160405-1820
                    Fragments=16
14      STARTING    org.eclipse.ecf.provider.filetransfer.httpclient4_1.1.100.v20160405-1820
                    Fragments=15
15      RESOLVED    org.eclipse.ecf.provider.filetransfer.httpclient4.ssl_1.1.0.v20160405-1820
                    Master=14
16      RESOLVED    org.eclipse.ecf.provider.filetransfer.ssl_1.0.0.v20160405-1820
                    Master=13
17      RESOLVED    org.eclipse.ecf.ssl_1.2.0.v20160405-1820
                    Master=10
18      STARTING    org.eclipse.equinox.app_1.3.400.v20150715-1528
19      ACTIVE      org.eclipse.equinox.common_3.8.0.v20160509-1230
20      STARTING    org.eclipse.equinox.concurrent_1.1.0.v20130327-1442
21      ACTIVE      org.eclipse.equinox.console_1.1.200.v20150929-1405
22      RESOLVED    org.eclipse.equinox.ds_1.4.400.v20160226-2036
23      STARTING    org.eclipse.equinox.frameworkadmin_2.0.300.v20160504-1450
24      ACTIVE      org.eclipse.equinox.frameworkadmin.equinox_1.0.700.v20160102-2223
25      RESOLVED    org.eclipse.equinox.launcher_1.3.200.v20160318-1642
                    Fragments=26
26      RESOLVED    org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.400.v20160518-1444
                    Master=25
27      STARTING    org.eclipse.equinox.p2.artifact.repository_1.1.500.v20160419-0834
28      ACTIVE      org.eclipse.equinox.p2.console_1.0.500.v20160504-1450
29      ACTIVE      org.eclipse.equinox.p2.core_2.4.100.v20160419-0834
30      STARTING    org.eclipse.equinox.p2.director_2.3.300.v20160504-1450
31      STARTING    org.eclipse.equinox.p2.engine_2.4.100.v20160419-0834
32      STARTING    org.eclipse.equinox.p2.garbagecollector_1.0.300.v20160504-1450
33      RESOLVED    org.eclipse.equinox.p2.jarprocessor_1.0.500.v20160504-1450
34      ACTIVE      org.eclipse.equinox.p2.metadata_2.3.100.v20160427-2220
35      STARTING    org.eclipse.equinox.p2.metadata.repository_1.2.300.v20160419-0834
36      STARTING    org.eclipse.equinox.p2.operations_2.4.200.v20160504-1450
37      ACTIVE      org.eclipse.equinox.p2.repository_2.3.200.v20160421-0324
38      STARTING    org.eclipse.equinox.p2.touchpoint.eclipse_2.1.400.v20160419-0834
39      STARTING    org.eclipse.equinox.p2.touchpoint.natives_1.2.100.v20160419-0834
40      STARTING    org.eclipse.equinox.p2.transport.ecf_1.1.200.v20160606-1311
41      STARTING    org.eclipse.equinox.preferences_3.6.0.v20160120-1756
42      ACTIVE      org.eclipse.equinox.registry_3.6.100.v20160223-2218
43      STARTING    org.eclipse.equinox.security_1.2.200.v20150715-1528
                    Fragments=44
44      RESOLVED    org.eclipse.equinox.security.win32.x86_64_1.0.100.v20130327-1442
                    Master=43
45      STARTING    org.eclipse.equinox.simpleconfigurator_1.1.200.v20160504-1450
46      ACTIVE      org.eclipse.equinox.simpleconfigurator.manipulator_2.0.200.v20160504-1450
47      STARTING    org.eclipse.equinox.util_1.0.500.v20130404-1337
48      RESOLVED    org.eclipse.osgi.services_3.5.100.v20160504-1419
49      RESOLVED    org.sat4j.core_2.3.5.v201308161310
50      RESOLVED    org.sat4j.pb_2.3.5.v201404071733
51      RESOLVED    org.tukaani.xz_1.3.0.v201308270617
 

使用Apache Felix

下载Apache Felix Framework Distribution并将其解压缩到一个目录中:

$ tar xf org.apache.felix.main.distribution-5.4.0.tar.gz
$ cd felix-framework-5.4.0

然后使用以下命令启动框架:

$ java -jar bin/felix.jar
____________________________
Welcome to Apache Felix Gogo
    
g!

默认情况下,Felix使用Apache Felix Gogo作为其交互式shell。默认命令提示符, g! ,如上所示。

Gogo shell提供了一些简单的内置命令,可以与Gogo运行时环境以及OSGi框架本身进行交互。在g! 输入help 命令g! 提示查看内置命令列表。

一个例子是lb列表包的简称)命令,它输出当前安装在框架中的OSGi包的列表:

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (5.4.0)|5.4.0
    1|Active     |    1|Apache Felix Bundle Repository (2.0.6)|2.0.6
    2|Active     |    1|Apache Felix Gogo Command (0.16.0)|0.16.0
    3|Active     |    1|Apache Felix Gogo Runtime (0.16.2)|0.16.2
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)|0.10.0