環(huán)境描述:
eclipse3.6
jdk1.6
最近由于項(xiàng)目需求,開始學(xué)習(xí)OSGI,手頭參考資料則為林昊老師的OSGI原理與最佳實(shí)踐這本書。該書由于發(fā)行較早,使用3.6版本的eclipse會(huì)遇到各種錯(cuò)誤。其中在采用Declarative Service 的方式來(lái)實(shí)現(xiàn)的時(shí)候按作者書上的步驟來(lái)則會(huì)報(bào)這么一個(gè)錯(cuò)誤。和同事探討了一下午的時(shí)間,原來(lái)是缺少一個(gè)jar。
先看下異常信息:
org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.ds_1.2.0.v20100507 [29]" could not be resolved. Reason: Missing Constraint: Import-Package: org.eclipse.equinox.internal.util.event; version="1.0.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1317)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1301)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:319)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:374)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1067)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:561)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:546)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:459)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:440)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:337)
!ENTRY org.eclipse.osgi 4 0 2010-09-07 08:35:43.000
!MESSAGE Bundle reference:file:/D:/eclipse/plugins/org.eclipse.equinox.ds_1.2.0.v20100507.jar was not resolved.
解決方案:
在eclipse的run configurations選項(xiàng)卡中勾選org.eclipse.equinox.util_1.0.200.v20100503.jar包即可,org.eclipse.equinox.util為固定部分,后者隨著eclipse版本的更新會(huì)有所變化。
最后完整的bundle應(yīng)該是這樣的: