`
snoopy7713
  • 浏览: 1124541 次
  • 性别: Icon_minigender_2
  • 来自: 火星郊区
博客专栏
Group-logo
OSGi
浏览量:0
社区版块
存档分类
最新评论

在Apache Felix中运行bundle

    博客分类:
  • OSGi
阅读更多

在前面搭建了一个Apache Felix的运行环境,下面就写一个简单的bundle,测试测试。

1、新建一个插件工程,如下图:


 

点击下一步。

2、给插件工程命名一个名字,这里叫pig1。This plug-in is targeted to run with中选择an OSGI framework -->standard,如下图红框中所示:


 

点击下一步。

3、bundle中有一个启动类,默认是Activator,相当于普通工程中的Main类。你也可以把它更改成其他名字,这里使用默认的名字。如下图:


 

点击下一步。

4、去掉Create a plug-in using one of the templates,如下图:


 

点击Finish。

5、插件工程建好后,打开Activator类,可以看到里面有一个start方法和一个stop方法,可以在bundle启动和停止的时候做一些事情。这里只是简单地输出一个字符串,作为bundle启动和停止时的标识。

Java代码  收藏代码
  1. /*  
  2.      * (non-Javadoc)  
  3.      *   
  4.      * @see  
  5.      * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext  
  6.      * )  
  7.      */   
  8.     public   void  start(BundleContext bundleContext)  throws  Exception  
  9.     {  
  10.         Activator.context = bundleContext;  
  11.         System.out.println("start pig1" );  
  12.     }  
  13.   
  14.     /*  
  15.      * (non-Javadoc)  
  16.      *   
  17.      * @see  
  18.      * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)  
  19.      */   
  20.     public   void  stop(BundleContext bundleContext)  throws  Exception  
  21.     {  
  22.         Activator.context = null ;  
  23.         System.out.println("stop pig1" );  
  24.     }  

 
 6、代码也写好后,就可以导出插件工程发布了。如何让这个工程作为一个bundle被部署到Felix容器中呢?右击插件工程pig1,选择Export。可看下图:


 

出现Export视图之后,选择Plug-in Development下的Deployable plug-ins and fragments,如下图:



 
点击下一步,选择要导出的插件,Destination选项卡的Directory选择我们的Felix环境的物理地址,导出后,会在Felix工程的根目录自动创建一个plugins目录,bundle会默认导出这个目录。如下图:


 

点击Finish,你就可以看到Felix工程下面多了一个plugins目录,我们所导出的bundle就在里面,如下图:


 

7、接着就是安装、运行了。

有三种方法可以安装、运行一个bundle。

(1)使用命令。

首先,启动Felix,在Console中先使用install命令安装bundle,接着使用start命令启动bundle,如下图:



 
启动的时候,start命令后接着那个bundle的启动ID就可以启动bundle了,如上图的12。

可以看到,当启动bundle的时候,输出了Activator类中start方法的输出语句,即"start pig1"。

Pig1的状态为Active,说明bundle启动成功了。

当然,你也可以使用uninstall命令卸载一个bundle,用法如install命令。

 

(2)使用Felix配置文件,打开conf/config.properties,如下图:


打开config.properties,找到felix.auto.start.1参数,值写成file:plugins/pig1_1.0.0.201109291700.jar,如:

(如果你有多个bundle,之间用空格隔开)。

 

参数代码  收藏代码
  1. # The following property is a space-delimited list of bundle URLs  
  2. # to install and start when the framework starts. The ending numerical  
  3. # component is the target start level. Any number of these properties  
  4. # may be specified for different start levels.  
  5. felix.auto.start.1 =file:plugins/pig1_1. 0.0 . 201109291700 .jar  

 

参数写好后,启动Felix,你就可以看到bundle Pig1自动安装并启动了,如下图所示:


(3)第三种方法就是使用File Install了,使用Apache Felix的File Install bundle,我们可以安装和启动bundle而无需启动Felix,这个将在下面的章节中讲解。

 

8、OK,完成了。

分享到:
评论
1 楼 chenyuguxing 2015-09-23  
你好, 为什么我的bundle export到felix工程中时 , 用lb查看不到呢?

相关推荐

    Apache Felix 框架整理包 开箱即用

    Apache Felix Web Console Bundle整理包 管理控制台 框架运行环境 idea使用集成包 包含两个demo实例

    gradle-felix-launcher-plugin:Gradle 构建系统的 Apache Felix 插件

    该插件允许创建 apache felix 框架安装以准备运行 osgi bundle 应用程序。 特征 Felix Launcher 插件的特点: 下载所需的 apache felix 框架包 felix 框架的配置、组装和执行 将自定义包编译并包含到 felix 框架中...

    File Install

    Apache Felix框架下bundle自动更新

    felix-atomos:Apache Felix原子

    例子有许多范例项目都包含在下面的文件夹的ATOMOS git仓库atomos.examples 。 从 运行使用从模块路径运行使用运行有关更多信息,请参见Atomos示例。模块路径和类路径用法扁平类路径或模块路径是使用Atomos的两种简单...

    quickwebframework

    支持所有实现OSGi R4 Service Platform规范的OSGi容器,如:Apache Felix、Equinox OSGi等。 模块化 在程序运行时可以任意安装,启用,停止,卸载WEB模块插件而不用重新启动WEB容器。变化即时生效。 依赖注入支持 ...

    rcp-demo:RCP演示

    RCP演示RCP 演示应用程序。 应用程序的特征被分成模块,... Apache Felix Bundle 插件/tycho 集成: 外部和测试项目不得具有 m2eclipse 或 pde 性质。 这会导致许多 Eclipse 验证错误。 项目的类路径由“mvn eclipse:ec

    OSGI原理与最佳实践(扫描版,带目录).pdf

    最后对0SGi知识进行深入讲解,通过对0SGi规范和实现框架(Equinox、Felix、Spring—DM和Apache CXF)的分析,以及最佳实践的介绍,帮助读者更好地使用OSGi。 OSGi原理与最佳实践 目录: 第1章 OSGi简介 第2章 OSGl...

    struts-2.5.2-all所有jar包

    org.apache.felix.framework-4.0.3.jar, org.apache.felix.main-4.0.3.jar, org.apache.felix.shell-1.4.3.jar, org.apache.felix.shell.tui-1.4.1.jar, org.osgi.compendium-4.0.0.jar, org.osgi.core-4.1.0.jar, ...

    struts-2.5.10-all所有jar包

    log4j-api-2.7.jar,ognl-3.1.12.jar,org.apache.felix.framework-4.0.3.jar,org.apache.felix.main-4.0.3.jar,org.apache.felix.shell-1.4.3.jar,org.apache.felix.shell.tui-1.4.1.jar,org.osgi.compendium-4.0.0....

    struts-2.3.30-all所有jar包

    org.apache.felix.framework-4.0.3.jar, org.apache.felix.main-4.0.3.jar, org.apache.felix.shell-1.4.3.jar, org.apache.felix.shell.tui-1.4.1.jar, org.osgi.compendium-4.0.0.jar, org.osgi.core-4.1.0.jar, ...

    OSGI in Action

    12.2 Apache Felix iPOJO 391 Building iPOJO components 392 ■ Providing services with iPOJO 393 Consuming services with iPOJO 395 ■ iPOJO component lifecycle 400 ■ Instantiating components with iPOJO...

    271个java需要用的jar包

    org.apache.felix.framework-4.0.3.jar org.apache.felix.main-4.0.3.jar org.apache.felix.shell-1.4.3.jar org.apache.felix.shell.tui-1.4.1.jar org.eclipse.emf.transaction_1.4.0.v20100331-1738.jar org....

Global site tag (gtag.js) - Google Analytics