几种OSGi框架

Several independently implemented OSGi frameworks exist today, including four that are available as open source software.
  • Equinox  is the most widely deployed OSGi framework today owing to its use in the core runtime of Eclipse. It can also be found in many in-house custom applications as well as packaged products such as Lotus Notes and IBM WebSphere Application Server. Equinox implements Release 4.1 of the OSGi specifications and is licensed under the Eclipse Public License (EPL).
  • Knopflerfish  is a popular and mature implementation of both OSGi Release 3 and Release 4.1 specifications. It is developed and maintained by Makewave AB, a company based in Sweden, and is licensed under a BSD-style license. Makewave also offers Knopflerfish Pro, a commercially supported version of Knopflerfish.
  • Felix  is a community implementation of the OSGi Release 4.x under the Apache Group umbrella. It is designed particularly for compactness and  ease of embedding, and is the smallest (in terms of minimal JAR size) of the Release 4 implementations. It is licensed under the Apache License Version 2.0.
  • Concierge  is a very compact and highly optimized implementation of OSGi Release 3. This makes it particularly suited to resource-constrained plat-forms such as mobile phones. Concierge is licensed under a BSD-style license.
 

下载Equinox框架

下载解压后,设置环境变量EQUINOX_HOME。

设置Eclipse

设置User Libraries,将Equinox目录下的plugins/org.eclipse.-osgi_version.jar 文件加入到用户库中。
接下来创建一个Java项目,命名为 “OSGi Tutorial” ;选择依赖上述User Library。

运行Equinox

We’re now going to run Equinox using the Eclipse launcher. We could run Equinox from a shell or command prompt window, but if we run under Eclipse we can easily switch to debugging mode when things go wrong.
 

Run Configuration

From the main menu, select Run → Run Configurations (or Open Run Dia-log in older Eclipse versions). On the left hand side select “Java Application” and click the “New” button. Change the Name field at the top to “Equinox”. Ensure the Project field is set to the “OSGi Tutorial” project, and then click the Search button next to the Main class field. The only available “main” class should be the one called EclipseStarter, so choose that one.
 
Now flip to the Arguments tap of the Run Configurations dialog. In the Program Arguments field enter the following arguments exactly:

−console −configuration runtime

  • The first argument -console indicates that Equinox should create an interactive console for us to work with – if we forget this argument then it will start up and then immediately exit!
  • The second argument (consisting of two words, -configuration runtime) asks Equinox to create its “configuration area” in a local directory named runtime. The configuration area is where Equinox stores its temporary state information.

Run

Now click Run. Equinox will print the following:

osgi >
This is Equinox’s standard shell prompt and indicates it is waiting for input from us. We are now ready to run some commands. The most frequently used command is ss, which prints the list of currently installed bundles along with their state. Let’s try running ss now:

osgi > ss

Framework is launched .

id State Bundle


ACTIVE org . eclipse . osgi_3 .
.
. v20090311 −

The only bundle here is Equinox itself, listed under the name of the Equinox JAR file. It is also called the
“System Bundle”, and it always has the bundle ID of zero.

Run from command line

For reference, if we wanted to run Equinox from the command line then we could do so as follows, assuming we have a shell variable named EQUINOX_HOME set to the installation directory we created earlier:

java −jar $EQUINOX_HOME
/ plugins
/ org.eclipse.osgi_∗.jar −console −configuration runtime

Install bundle

For the moment, there is not much more we can do with Equinox until we install some more interesting bundles. However you may at this point wish to explore the commands available by typing help. When bored with this, don’t shutdown Equinox just yet; leave it running for now.
 
我们先创建一个bundle,名为helloworld.jar。BundleActivator如下:

package org.osgi.tutorial ;


import org.osgi.framework.BundleActivator ;


import org.osgi.framework.BundleContext ;


public
class HelloWorldActivator
implements BundleActivator {

   
public
void start ( BundleContext context )
throws Exception {

      System.out.println (
" Hello , World !" ) ;

  }

   
public
void stop ( BundleContext context )
throws Exception {

      System.out.println (
" Goodbye , World !" ) ;

  }

}

 
Now we can try installing this bundle into Equinox, which you should still have running from the previous section (if not, simply start it again). At the Equinox shell prompt, type the command:

install file
: helloworld . jar

Equinox will respond with the bundle ID that it has assigned to the bundle:

Bundle id is

 
Let’s take a quick look at the bundle list by typing ss. It should look like this:

Framework is launched .

id State Bundle


ACTIVE org . eclipse . osgi_3 .
.
. v20090311 −

INSTALLED helloworld_0 .
.

 

Start bundle

Now the moment of truth: start the new bundle by typing start 1. We should see:

osgi
> start

Hello , World
!

 
What does the bundle list look like now if we type ss? We’ll ignore the rest of the listing, as it hasn’t changed, and focus on our bundle:

ACTIVE helloworld_0 .
.

 

Stop bundle

The bundle is now in the “ACTIVE” state, which makes sense since we have explicitly started it. Now stop the bundle with stop 1:

osgi
> stop

Goodbye , World
!

 
This works as expected. What does the bundle list look like now?

RESOLVED helloworld_0 .
.

 
This is interesting. When we started the bundle it changed its state from Installed to Active, but when we stopped the bundle it didn’t go back to Installed: instead it went to a new state “RESOLVED”.
refer to: OSGi生命周期

 
 
 
 
 
 
 
 
 
 

基于Equinox构建OSGi项目的更多相关文章

  1. Jenkins:基于linux构建ivy项目

    Jenkins:基于linux构建ivy项目 (二) 基于以上<Jenkins:VMware虚拟机Linux系统的详细安装和使用教程(一)>的配置再进行对ivy项目构建: 启动tomcat ...

  2. 基于已构建S2SH项目配置全注解方式简化配置文件

    如果还不熟悉s2sh项目搭建的朋友可以先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 eclipse环境下基于已构建struts2项目整合spring+hiberna ...

  3. 基于 Equinox 的 OSGi Console 的研究和探索

    自定制 OSGi Console 进行组建和服务生命周期管理模块化编程的好处已经很好地被理解了约 40 年,但在 OSGi 之前,开发人员不得不自己发明模块化设计和系统.随着软件应用体系结构的不断发展 ...

  4. eclipse环境下基于已构建struts2项目整合spring+hibernate

    本文是基于已构建的struts2项目基础上整合 spring+hibernate,若读者还不熟悉struts2项目,请先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 ...

  5. 基于dubbo构建分布式项目与服务模块

      关于分布式服务架构的背景和需求可查阅http://dubbo.io/.不同于传统的单工程项目,本文主要学习如何通过maven和dubbo将构建分布项目以及服务模块,下面直接开始. 创建项目以及模块 ...

  6. 基于Maven构建Web项目

    1.下载Maven,并配置好环境变量 2.打开命令行窗口,输入以下命令构建Maven Web项目 mvn archetype:generate -DgroupId=com.hello -Dartifa ...

  7. 【转载】基于webpack构建react项目

    第一部分链接:下载所需内容并构建基础的页面 第二部分链接:添加webpack中的一些常用babel和loader 第三部分链接:开发环境与生产环境的配置

  8. 基于maven构建javaweb项目思路梳理及改进

    需要准备的东西: Jdk. myeclipse. maven包 预装jdk环境 1.maven安装及配置: a)      详见url https://www.cnblogs.com/eagle668 ...

  9. 基于Maven构建的Spring+Mybatis项目

    项目的目录结构: 1.基于Maven构建Web项目 参考:基于Maven构建Web项目 2.导入项目依赖 Spring 核心容器(Beans.Core.Context.Context support. ...

随机推荐

  1. Template Method 模板方法

      简介 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中. 模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤的细节 抽象模板AbstractClass的方法分为两类: 基本 ...

  2. Java中的浅复制和深复制 Cloneable clone

    先看一个简单案例 public class Test {     public static void main(String args[]) {         Student stu1 = new ...

  3. surfaceView和Camera配合进行摄像头的预览

    首先是Camera类,在5.0上已经被废弃,不推荐使用但还是支持的.最新的是Camera2类,我还没有研究,据说用法完全不一样,反正也是一个坑跳入另外一个坑. 上面是简介和需要的权限,记得加上权限. ...

  4. Windows XP CD 函数不正确

    参考这篇文章:http://support.hp.com/cn-zh/document/c00760286 一,在设备管理中查看,如果刻录机名称中含 ROM,则需确认设备是否可写 二,若确定设备可写, ...

  5. ie浏览器下input和select的上下居中问题!!!!

    在Google浏览器下的input和select标签里面的文字是根据它的高度自适应上下居中的,而ie浏览器下的input和select里面的文字就不会根据高度自适应上下居中,跟大家分享一下我的解决方法 ...

  6. 正则表达式中/i,/g,/m的作用

    一./i (ignorCase)忽略大小写,注意仅是忽略大小写,并不忽略全半角. 二./g (globle)全文查找出现的所有匹配字符 三./m 1.(mutiple)多行查找2.m 影响 ^.$.3 ...

  7. 千万数量级分页存储过程 +AspNetPager现实分页

    存储过程 USE [ForeignTradeDB] GO /****** Object: StoredProcedure [dbo].[CommonGetDataPager] Script Date: ...

  8. 各浏览器对 onbeforeunload 事件的支持与触发条件实现有差异

    转载:http://www.w3help.org/zh-cn/causes/BX2047 标准参考 无. 问题描述 一般情况下,onbeforeunload 事件处理函数内会写入一些提示性语句,当用户 ...

  9. [转]Delphi 关键字详解

    全文链接地址:http://www.cnblogs.com/del/archive/2008/06/23/1228562.html

  10. HTTP 状态响应码 意思详解/大全

    HTTP 状态响应码 意思详解/大全 转:http://blog.csdn.net/helin916012530/article/details/29842595 HTTP状态码(HTTP Statu ...