我的目标是从我的包中删除对 OSGi 的依赖。我使用 felix (v 4.2.1) 作为 impl 并运行它可嵌入的。我安装org.apache.felix.scr
(v. 1.6.2)捆绑包以获得服务组件运行时支持。但是当我跑步时
ServiceReference ref = bundleContext().getServiceReference(ScrService.class.getName());
ScrService s = (ScrService) bundleContext().getService(ref);
我明白了ClassCastException: org.apache.felix.scr.impl.ComponentRegistry cannot be cast to org.apache.felix.scr.ScrService
。
好的。我将修改系统包。
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.apache.felix.scr");
现在我明白了
Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle org.apache.felix.scr [1]: Unable to resolve 1.0: missing requirement [1.0] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.4.0)(!(version>=2.0.0)))
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
at com.copyright.rup.communications.felix.Felix.addBundle(Felix.java:86)
... 28 more
我该如何解决?