RCP中如何使用代码安装、运行plugins

简介: 其实在google或者http://www.eclipse.org/forums/就能够找到这个问题的答案。 搜索关键字:rcp install plugins\bundles programmatically   大部分的操作都能在org.osgi.framework.Bundle这个接口里找到,比如start、stop、uninstall等等。

其实在google或者http://www.eclipse.org/forums/就能够找到这个问题的答案。

搜索关键字:rcp install plugins\bundles programmatically
 
大部分的操作都能在 org.osgi.framework.Bundle 这个接口里找到,比如start、stop、uninstall等等。
如果对这几个术语不熟悉,请找一本《OSGI最佳原理与实践》,详细阅读OSGI的生命周期相关内容。
 
Bundle接口也维护了所有的生命周期的状态常量比如:
    int    UNINSTALLED                = 0x00000001;

 

Bundle的获取代码如下所示:
org.eclipse.core.runtime.Platform.getBundle(String symbolicName)

 

Platform是eclipse平台运行时的核心类,它是静态的不允许继承的,它的内部方法全部是静态方法。即是说,只要你依赖了org.eclipse.core.runtime插件,你可以在任何地方无条件的使用该类的所有公开静态方法。

symbolicName是指插件的插件名,比如org.eclipse.core.runtime_3.7.0.v20110110的插件名即是org.eclipse.core.runtime。

获取Bundle之后,你就可以对该bundle做任何你爱做的事,但是,不包括安装!

 

我们再看回Bundle插件,注意它的类注释的第一条:

“An installed bundle in the Framework.”

这一句说明,Bundle接口是已经安装的bundle实体,在一个插件jar包还没有被安装的时候,自然不构成Bundle。

我们要如何安装它呢?

找到org.osgi.framework.BundleContext接口。

BundleContext methods allow a bundle to: 

Subscribe to events published by the Framework. 
Register service objects with the Framework service registry. 
Retrieve ServiceReferences from the Framework service registry. 
Get and release service objects for a referenced service. 
Install new bundles in the Framework. 
Get the list of bundles installed in the Framework. 
Get the Bundle object for a bundle. 
Create File objects for files in a persistent storage area provided for the bundle by the Framework. 

看到红色字体了吗?

为此,BundleContext提供了两个方法:

    Bundle installBundle(String location, InputStream input)
            throws BundleException;

    Bundle installBundle(String location) throws BundleException;

具体的使用请自行参考注释。

 

如何获取BundleContext呢?

你可以使用一个现存的Bundle来getBundleContext,也可以在你的插件激活器(Activator,如果这个不清楚是什么,请回炉)中直接使用start方法的参数BundleContext。

当然以上两种方法是等效的。

 

 

 

 

 

 
 
 
目录
相关文章
|
安全 C++ Windows
好工具推荐系列:VC++开发必备神器 -- Dependencies,查看依赖库DLL,支持win10,比depends更好用
好工具推荐系列:VC++开发必备神器 -- Dependencies,查看依赖库DLL,支持win10,比depends更好用
2164 0
好工具推荐系列:VC++开发必备神器 -- Dependencies,查看依赖库DLL,支持win10,比depends更好用
|
人工智能 Linux Python
代码自动补全工具——Kite安装教程(以Pycharm为例)及Failed to install PyCharm at path.Plugin configuration directory的解决方案
代码自动补全工具——Kite安装教程(以Pycharm为例)及Failed to install PyCharm at path.Plugin configuration directory的解决方案
代码自动补全工具——Kite安装教程(以Pycharm为例)及Failed to install PyCharm at path.Plugin configuration directory的解决方案
|
8月前
JRebel and xrebel 热部署插件 激活时出现LS client not configued 报错解决
JRebel and xrebel 热部署插件 激活时出现LS client not configued 报错解决
480 0
|
8月前
JRebel and xrebel 热部署插件 激活时出现LS client not configued 报错
JRebel and xrebel 热部署插件 激活时出现LS client not configued 报错
319 0
|
4月前
|
并行计算 监控 Shell
openwrt编译模块demo练习
openwrt编译模块demo练习
50 0
|
10月前
|
安全 编译器 Linux
别忘了给gcc编译器工具链加上-fno-common选项
别忘了给gcc编译器工具链加上-fno-common选项
简单方便的jar包启动的sh脚本
简单方便的jar包启动的sh脚本
|
网络协议 安全 Unix
源代码配置安装Apache
Apache(音译为阿帕奇)是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。
源代码配置安装Apache
|
资源调度 索引
Cypress系列(98)- cypress-xpath 插件, xpath() 命令详解
Cypress系列(98)- cypress-xpath 插件, xpath() 命令详解
338 0
Cypress系列(98)- cypress-xpath 插件, xpath() 命令详解