OSGi#1:Equinox 初探
来源:互联网 发布:淘宝直通车 如何出价 编辑:程序博客网 时间:2024/05/19 06:50
From a code point of view, Equinox is an implementation of the OSGi core framework specification, a set of bundles that implement various optional OSGi services and other infrastructure for running OSGi-based systems.
上面是Equinox官网的描述,Equinox是一个OSGi实现,具体就不赘述了,下面来看看Equinox该怎么玩,直接上代码。
按照惯例,来个Hello World
的栗子。先打出一个输出Hello World
的bundle,
package me.kisimple.just4fun.osgi;import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;public class IBundleActivator implements BundleActivator { @Override public void start(BundleContext bundleContext) throws Exception { System.out.println("Hello,World."); } @Override public void stop(BundleContext bundleContext) throws Exception { System.out.println("Goodbye,World."); }}
MANIFEST.MF
这么写,
Manifest-Version: 1.0Bundle-ManifestVersion: 2Bundle-Name: HelloWorldBundle-SymbolicName: me.kisimple.just4fun.osgi.HelloWorldBundle-Version: 1.0.0Bundle-Activator: me.kisimple.just4fun.osgi.IBundleActivatorBundle-Vendor: KISIMPLEBundle-Localization: systembundleImport-Package: org.osgi.framework
然后打包,
> jar cvfm me.kisimple.just4fun_1.0.0.jar MANIFEST.MF me\kisimple\just4fun\osgi\IBundleActivator.class
接下来需要去官网下载Equinox的SDK,我下的是equinox-SDK-LunaSR2.zip。然后参考官网的quick start文档,我们新建一个container
目录,该目录有如下文件,
E:\Projects> tree container /FE:\PROJECTS\CONTAINER│ org.eclipse.equinox.common_3.6.200.v20130402-1505.jar│ org.eclipse.osgi_3.10.2.v20150203-1939.jar│ org.eclipse.update.configurator_3.3.300.v20140518-1928.jar│├─configuration│ config.ini│└─plugins me.kisimple.just4fun_1.0.0.jar org.apache.felix.gogo.command_0.10.0.v201209301215.jar org.apache.felix.gogo.runtime_0.10.0.v201209301036.jar org.apache.felix.gogo.shell_0.10.0.v201212101605.jar org.eclipse.equinox.console_1.1.0.v20140131-1639.jar
除了me.kisimple.just4fun_1.0.0.jar
跟org.eclipse.update.configurator_3.3.300.v20140518-1928.jar
,其他jar包都是从下载下来的SDK中可以拿到的,me.kisimple.just4fun_1.0.0.jar
是上面我们打的输出Hello World
的bundle,而org.eclipse.update.configurator_3.3.300.v20140518-1928.jar
则是从eclipse(忘记安装的是哪个版本了>_<)的安装目录下的plugins
目录中获取(本身eclipse也使用了Equinox,所以也有configuration/config.ini
文件和plugins
目录)。
configuration/config.ini
如下,
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start
alright,接下来就可以启动Equinox了,
E:\Projects\container>java -jar org.eclipse.osgi_3.10.2.v20150203-1939.jar -consoleosgi> _
org.eclipse.osgi_3.10.2.v20150203-1939.jar
的Main-Class
是org.eclipse.core.runtime.adaptor.EclipseStarter
,除了-console
,还支持一些其他选项。源码可以使用git
获得,
> git clone http://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
接下来可以在命令行中启动我们的bundle了。先用ss
命令看下bundle的情况,
osgi> ss"Framework is launched."id State Bundle0 ACTIVE org.eclipse.osgi_3.10.2.v20150203-19391 ACTIVE org.eclipse.equinox.common_3.6.200.v20130402-15052 ACTIVE org.eclipse.update.configurator_3.3.300.v20140518-19283 RESOLVED me.kisimple.just4fun.osgi.HelloWorld_1.0.04 ACTIVE org.apache.felix.gogo.command_0.10.0.v2012093012155 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v2012093010366 ACTIVE org.apache.felix.gogo.shell_0.10.0.v2012121016057 ACTIVE org.eclipse.equinox.console_1.1.0.v20140131-1639
启动我们的bundle,
osgi> start 3Hello,World.
这时候再用ss
命令可以看到我们的bundle的状态变成了ACTIVE
了,
3 ACTIVE me.kisimple.just4fun.osgi.HelloWorld_1.0.0
停掉我们的bundle,
osgi> stop 3Goodbye,World.
这时候bundle的状态就会又回到了RESOLVED
。
参考资料
- http://eclipse.org/equinox/resources.php
- http://eclipse.org/equinox/documents/quickstart-framework.php
- http://www.javaworld.com/article/2077837/java-se/hello–osgi–part-1–bundles-for-beginners.html
- http://developer.51cto.com/art/200909/152209.htm
- http://moi.vonos.net/java/osgi-classloaders/
- OSGi#1:Equinox 初探
- Equinox OSGi
- 初探OSGi Web应用开发利器Equinox:环境设置
- 初探OSGi Web应用开发利器Equinox:环境设置
- OSGI之Debug Equinox
- Eclipse 、 Equinox 和 OSGi
- equinox的osgi命令
- OSGI Equinox 环境搭建
- osgi equinox helloword
- Equinox 和 OSGI 介绍
- OSGI EQUINOX 参数配置
- 使用equinox开发osgi
- Equinox OSGi系列之一 Equinox入门
- Equinox OSGi系列之一 Equinox入门
- Equinox OSGi系列之一 Equinox入门
- Equinox OSGi系列之二 搭建Equinox OSGi核心环境
- Equinox OSGi系列之二 搭建Equinox OSGi核心环境
- OSGi原理与最佳实践:第一章 OSGi框架简介(1)Equinox
- Android SDK 在线更新镜像服务器资源
- 替换字符串,裁掉字符串两端的空格---轻开平台(原WebEasy)字符串计算6
- poj 3693 Maximum repetition substring(08合肥 RMQ+后缀数组)
- Java 序列化与反序列化
- 习题10-18 一个研究课题 UVa10837
- OSGi#1:Equinox 初探
- 最短路dij——POJ 2387 Til the Cows Come Home题解
- 【SPFA】最短路 _HDU2544
- 阿里面试
- SQLite的基本封装
- 写一下单例模式,考虑线程安全与线程不安全的情况
- 我的手机必备App
- java Iterator.remove() 方法的用途
- SQL Server 2014创建分区表