[OSGI] Felix基本环境搭建及操作

Felix是Apache旗下的一款实现OSG规范I的框架。访问地址:http://felix.apache.org/


搭建基本的OSGI框架只需要下载Felix Framework


下载完成后解压至任意目录(如:D:\felix-framework-4.4.1),在felix-framework-4.4.1目录下打开CMD命令窗口,执行启动Felix框架命令

java -jar bin/felix.jar

完成启动后输入 lb 命令查看当前启动Felix的bundle

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
g!

停止Felix框架是输入 stop 0


安装Felix的bundle(helloworld.jar)是需要bundle的绝对路径,执行命令install file:/file_path

<pre name="code" class="plain">g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
g! install file:/d:/felix-framework-4.4.1/myplugins/helloworld_1.0.0.201501121409.jar
Bundle ID: 5 
g!

 

执行lb查看安装结果

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    5|Installed  |    1|Helloworld (1.0.0.201501121409)
g!
可以看出新安装的helloworld.jar的状态为Installed


启动bundle命令start bundleID

g! start 5
Hello world!
g!

查看bundle状态 lb

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    5|Active     |    1|Helloworld (1.0.0.201501121409)
g!
helloworld bundle状态为Active表示插件已激活


停止bundle命令为stop bundleID

g! stop 5
g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    5|Resolved   |    1|Helloworld (1.0.0.201501121409)
g!
helloworld bundle状态变为Resolved


更新helloworld的源码,输出语句变为Hello World, OSGI !

更新操作分为两种方法


将修改后的bundle替换原有bundle时,执行update bundleID

g! update 5
g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    5|Installed  |    1|Helloworld (1.0.0.201501121422)
g! start 5
Hello World, OSGI !
g!

将现有bundle跟新至另一个位置的存放的bundle,执行 update bundleID file:/fiel_path

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    5|Active     |    1|Helloworld (1.0.0.201501121409)
g! update 5 file:/d:/felix-framework-4.4.1/myplugins/helloworld_1.0.0.201501121409_new.jar
Hello World, OSGI !
g!

卸载bundle 命令 uninstall bundleID

g! uninstall 5
g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.4.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    2|Active     |    1|Apache Felix Gogo Command (0.14.0)
    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)
g!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值