Java OSGi 入门

OSGi 的核心就是一个 JVM 里的 Map<Service,ServiceImpl>.
重点在于向这个 Map 注册和注销 Service.


Equinox 的实现是:
引用

private HashMap<ServiceRegistrationImpl<?>, ServiceUse<?>> servicesInUse;


入门搭建参照:
引用
http://osgi.com.cn/article/7289228


上面的文章使用的是 3.7 ,我用的是 3.8

期间执行命令时无反应
引用
java -jar org.eclipse.osgi-3.8.0.v20120529-1548.jar -console


.\configuration\ 下面有 log,
出现错误.

引用
org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console


然后按照此方式解决.
http://stackoverflow.com/questions/11161871/org-osgi-framework-bundleexception-could-not-find-bundle-org-eclipse-equinox-c


大意就是 3.8 把 eclipse.console 从 equinox 中移除了, 需要额外的bundle
org.eclipse.equinox.console
org.apache.felix.gogo.runtime
org.apache.felix.gogo.shell
org.apache.felix.gogo.command
(command 这个有的说需要,有的说不用,我这里没用也可以,用了也没关系...)

-------------------------------------------------------------------------------------------------------------------
下面是在 Eclipse 里调试.

发现问题:
引用
Could not find bundle: org.eclipse.equinox.console


原因和上面一样的.解决办法:
下载  equinox-SDK-3.8.zip , plugins 文件夹下有 org.eclipse.equinox.console 以及 org.apache.felix.gogo.几个 jar ,把那几个 jar 放到相同的目录下, 就是 org.eclipse.osgi_3.8.0.v20120529-1548.jar 所在的目录.这时候

Run as -> run Configuration -> OSGi Framework 会多出几个 bundle , 都勾选上就可以了.

另外源码都在 SDK 那个压缩包里.
比如
引用
org.eclipse.osgi.source_3.8.0.v20120529-1548.jar

猜你喜欢

转载自id-alex.iteye.com/blog/1931222