【osgi】第一个bundle helloworld(2)

  接【osgi】第一个bundle helloworld(1)

  在eclipse新建bundle其实很简单,新建一个插件工程如下图。

provider为发布这个bundle的公司名称,Activator可以不改。

点击finish,创建bundle就完成了。接下来做一些小处理以后把bundle运行起来。

找到src下面的Activator.java。打开可以看到start和stop方法,start在bundle启动时运行,stop在bundle停止时运行。添加代码如下:

	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
		System.out.println("Hello world!!!");
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
		System.out.println("Goodbye world!!!");
	}
然后保存,运行方法在bundle helloworld(1)中已经提到,不同地方是需要把helloworld bundle也选中,如下图。

点击run,看到osgi> Hello world!!!表示已经成功。

下面介绍一下osgi console的部分命令,现在你可以在helloworld直接尝试

    • ss: 该命令显示所有已安装的Bundles及它们的状态,它将显示Bundle ID,Bundle的简短名称及Bundle状态;  
    • start<bundleid>: 该命令将启动一个Bundle;  
    • stop<bundleid>: 该命令将停止一个Bundle;  
    • update<bundleid>: 该命令使用新的JAR文件更新一个Bundle;  
    • install<bundleid>: 该命令将一个新的Bundle安装到OSGi容器;  
    • uninstall<bundleid>: 从OSGi容器中卸载一个已安装的Bundle。  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zfpigpig

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值