Eclipse学习笔记--有关Bundle

本文介绍在Eclipse 3.1之后,如何通过实现BundleActivator接口或继承Plugin类来管理OSGi Bundle。文章详细解释了如何通过Manifest.MF文件指定Bundle-Activator,并提供了停止特定Bundle的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

eclipse 3.1以后,bundle(osgi的概念)与原有的plugin成为可互换的名字.eclipseAPI,存在Plugin类和Bundle.其中,Plugin类里的方法已经逐步被废弃使用.

<o:p> </o:p>

建立一个可以管理bundle的类有两种方式:

a.继承 Plugin

b.实现 BundleActivator 接口.

其中,如果我们在创建一个plug-in project,选择了创建Activator,则该类就是继承Plugin.

<o:p> </o:p>

如何调用管理bundle的类?

Menifest.MF文件中指定:

Bundle-Activator: com.helloworld.MyBundle<o:p></o:p>

(自动创建时为: Bundle-Activator: com.helloworld.Activator)

这样设置完成后,再次触发该bundle的时候,就可以看到在Bundle 的start()方法中System.out.println()出来的信息,说明我们的bundle已经启动。

知道了这些,我们就可以控制一个Bundle的启动与停止了,下面的代码是停止的例子:

Button bn=new  Button(parent,0);
        bn.setText("stop the bundle");
        bn.addSelectionListener(new SelectionListener(){
   public void widgetDefaultSelected(SelectionEvent e) {
   }
   public void widgetSelected(SelectionEvent e) {

    //关闭当前view
    IWorkbenchPage page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart v=page.findView("com.singba.learing.helloworld.views.HelloworldView");
    page.hideView(v);
    

// 停止bundle
    Bundle mybundle=Platform.getBundle("com.singba.learing.helloworld");
    try {
     mybundle.stop();
    } catch (BundleException e1) {
     e1.printStackTrace();
    }
   }
         
        });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值