在IntelliJ Idea 12 里面使用OSGI -hello world

由于个人还是比较喜欢使用idea ,所以mark的内容也是用idea作为IDE的..这里只是简单的跑一个osgi的helloworld程序.至于osgi的理论性知识,可以到 http://developer.51cto.com/art/200909/154863.htm 查看.感觉写的很不错.

 

 

1 我使用的是equinox作为我的osgi framework ,所以,需要首先下载对应的 famework distribution.下载地址是

http://download.eclipse.org/equinox/  

我下载的版本为3.8.2,最后的目录结构为



 2 创建一个最简单的工程.



 3 创建 osgi-framework definitions .具体如下 .这个配置只需要一次.是IDE级别的.



 4 添加依赖,比较简单,看图就行..(这个图只是展示创建一个global 的lib依赖,还需要自己添加到工程里的,这个玩idea的应该都知道)



 

5 创建我们的 HelloWorldActivator.一个简单的java类而已.

package zhenghui.helloword;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

/**
 * User: zhenghui
 * Date: 13-6-24
 * Time: 下午7:29
 */
public class HelloWorldActivator implements BundleActivator {
    @Override
    public void start(BundleContext context) throws Exception {
        System.out.println("Hello World Bundle started!");
    }

    @Override
    public void stop(BundleContext context) throws Exception {
        System.out.println("Hello World Bundle stop!");
    }
}

 6 在module 的属性OSGI中, 设置 Bundle Activator为 HelloWorldActivator , 名字自己随意填写一个.



 

7 在configurations 里新增一个osgi bundle



 

8 最后run就OK了.貌似我的容器中,自动帮我加载了N多的bundle啊.



 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值