`

equinox在standalone application中启动

    博客分类:
  • osgi
阅读更多

     前一段时间,利用Felix作为osgi container,测试了osgi bundle的开发,并通过和springdm的结合,实现对于service发布和引用的实现。

     现在希望把以前实现的一些bundle和界面显示结合起来,当然可以把Felix Container和应用bundle发布在Web Container中,然后通过Client端(可以是RCP或者Browser)来显示内容,但是作为一个技术研究方向,如何实现这些bundle在Eclipse Equinox中应用,一直困扰着我,于是想把通过Eclipse RCP显示内容和Equinox的应用结合起来,实现这两方面技术的融合。

     作为bundle能够在java程序中运行的第一步,就是需要在java程序中,把Equinox osgi container启动起来和加载自己实现的bundle。在Eclipse的例子中有一个:org.eclipse.equinox.servletbridge实现了在Web Container中启动Equinox Container,可惜的是,这个例子中应用的Equinox版本较低,和我目前应用的Eclipse3.5版本不一致(在作Felix的时候也遇到了相同的问题,例子是1.x版本的,但是在2.0版本时,Felix做了很大的结构调整),所以想拿现成的例子不现实了。

      于是就自己开始动手,尝试实现Equinox嵌入到普通的Java Application中。在前面的例子中提到了在Java Application中启动Equinox利用EclipseStarter(org.eclipse.core.runtime.adaptor.EclipseStarter,看来Equinox还是主要服务Eclipse了,否则为什么不叫EquinoxStarter,其实在刚开始寻找入口时,我的确是去找这样的一个类了,很杯具),其中有一个main函数,可以直接的执行,在最初的实验中,执行这个main总是报错:

!ENTRY org.eclipse.osgi 4 0 2011-09-15 16:27:22.610
!MESSAGE Application error
!STACK 1
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
    at EclipseStarter.run(EclipseStarter.java:372)
    at EclipseStarter.run(EclipseStarter.java:181)
    at EclipseStarter.main(EclipseStarter.java:152)
     同时,也无法得到osgi的控制台,不知道是否Equinox启动成功,也不知道自己的bundle是否已经加载,很是郁闷!按照错误的内容只能去仔细的分析config.ini中的配置了,配置很多很多,eclipse的help中有具体的解释。

    通过阅读帮助,发现了一个eclipse.ignoreApp的配置参数,如下的解释:

if set to "true" then the main launching thread will not start the default application and will proceed in shutting down the platform and exiting. The default value is "false". This is different than the eclipse.application.launchDefault option because the main thread will not wait for an application descriptor service to be launched

      看了半天,好像和上面的问题没有关系,试着设了一下:eclipse.ignoreApp=true。这个错误不报了!在认真地分析一下,认为这个参数是控制Equinox Container是否启动Eclipse的开关,如果为true,则只启动Osgi Container,而不启动Eclipse的应用了,所以就不报错了,按照这样的逻辑,通过这样的设置,Equinox Container作为System bundle应当启动成功了。

     可是看不到osgi的控制台,无法看到bundle的状态,就无法判断了。继续深入学习config.ini文件的配置项,发现了osgi.console,需要设置一个端口,于是设置了一个9090,启动时显示Listening on port 9090 ... ,应当通过telnet可以练上去。

      真没想到在win7的command窗口输入telnet后竟然说找不到这个指令,连忙上网查了一下,原来win7为了安全的原因,竟然默认情况下没有安装telnet!只能装一下了,不过又解决了操作系统的一个问题。装好后,在command上执行:

telnet localhost 9090,终于见到了久违的 "osgi>";利用ss查了一下,系统bundle和自己写的测试bundle状态正常,说明,在java application中启动Equinox Container成功了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics