环境描述:
eclipse3.6
jdk1.6
最近由于项目需求,开始学习OSGI,手头参考资料则为林昊老师的OSGI原理与最佳实践这本书。该书由于发行较早,使用3.6版本的eclipse会遇到各种错误。其中在采用Declarative Service 的方式来实现的时候按作者书上的步骤来则会报这么一个错误。和同事探讨了一下午的时间,原来是缺少一个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选项卡中勾选org.eclipse.equinox.util_1.0.200.v20100503.jar包即可,org.eclipse.equinox.util为固定部分,后者随着eclipse版本的更新会有所变化。
最后完整的bundle应该是这样的: