在 OSGI 包中使用外部 java 库
Using an external java library in OSGI bundle
我想在我的 OSGI 包中使用这个 java 库 [1]enj-library,它将在 KURA eclipse 平台下执行。
我把库编译成jar然后在eclipse下新建了一个插件项目"Plug-in from existing JAR archive"
然后我尝试将它添加到我的包中,但没有成功:
1.I 尝试导入包,我验证了导入和导出的清单文件中的版本都是正确的,但我收到了这个错误:
org.osgi.framework.BundleException: The bundle "org.eclipse.kura.binding.enocean_1.0.0.201506181418 [70]" could not be resolved. Reason: Missing Constraint: Import-Package: it.polito.elite.enocean.enj.communication; version="1.0.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
at org.tigris.mtoolkit.iagent.internal.rpc.RemoteBundleAdminImpl.startBundle(RemoteBundleAdminImpl.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.tigris.mtoolkit.iagent.internal.pmp.InvocationThread.run(InvocationThread.java:54)
at org.tigris.mtoolkit.iagent.internal.utils.ThreadPool$Worker.run(ThreadPool.java:179)
at java.lang.Thread.run(Thread.java:724)
2.I 将其添加为必需的包,但我遇到了同样的错误:
org.osgi.framework.BundleException: The bundle "org.eclipse.kura.binding.enocean_1.0.0.201506181349 [70]" could not be resolved. Reason: Missing Constraint: Require-Bundle: EnOceanJavaLibraryplugIn; bundle-version="1.0.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
at org.tigris.mtoolkit.iagent.internal.rpc.RemoteBundleAdminImpl.startBundle(RemoteBundleAdminImpl.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.tigris.mtoolkit.iagent.internal.pmp.InvocationThread.run(InvocationThread.java:54)
at org.tigris.mtoolkit.iagent.internal.utils.ThreadPool$Worker.run(ThreadPool.java:179)
at java.lang.Thread.run(Thread.java:724)
3.I 添加到 class 路径中,我的包启动了,但我得到了 class 未找到异常
java.lang.ClassNotFoundException: org.eclipse.kura.binding.enocean.EnOcean
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:340)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1212)
at org.eclipse.equinox.internal.ds.model.ServiceComponent.createInstance(ServiceComponent.java:493)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.createInstance(ServiceComponentProp.java:272)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:333)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
[1]https://github.com/dog-gateway/enj-library
如何将此库包含在我的 OSGI 包中?
非常感谢您的帮助!
enocean 库似乎是一个 OSGi 包。所以你应该把它添加到你的目标平台,并在你自己的包中使用 Import-Package 来访问你需要的包。
我想在我的 OSGI 包中使用这个 java 库 [1]enj-library,它将在 KURA eclipse 平台下执行。
我把库编译成jar然后在eclipse下新建了一个插件项目"Plug-in from existing JAR archive"
然后我尝试将它添加到我的包中,但没有成功: 1.I 尝试导入包,我验证了导入和导出的清单文件中的版本都是正确的,但我收到了这个错误:
org.osgi.framework.BundleException: The bundle "org.eclipse.kura.binding.enocean_1.0.0.201506181418 [70]" could not be resolved. Reason: Missing Constraint: Import-Package: it.polito.elite.enocean.enj.communication; version="1.0.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
at org.tigris.mtoolkit.iagent.internal.rpc.RemoteBundleAdminImpl.startBundle(RemoteBundleAdminImpl.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.tigris.mtoolkit.iagent.internal.pmp.InvocationThread.run(InvocationThread.java:54)
at org.tigris.mtoolkit.iagent.internal.utils.ThreadPool$Worker.run(ThreadPool.java:179)
at java.lang.Thread.run(Thread.java:724)
2.I 将其添加为必需的包,但我遇到了同样的错误:
org.osgi.framework.BundleException: The bundle "org.eclipse.kura.binding.enocean_1.0.0.201506181349 [70]" could not be resolved. Reason: Missing Constraint: Require-Bundle: EnOceanJavaLibraryplugIn; bundle-version="1.0.0"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
at org.tigris.mtoolkit.iagent.internal.rpc.RemoteBundleAdminImpl.startBundle(RemoteBundleAdminImpl.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.tigris.mtoolkit.iagent.internal.pmp.InvocationThread.run(InvocationThread.java:54)
at org.tigris.mtoolkit.iagent.internal.utils.ThreadPool$Worker.run(ThreadPool.java:179)
at java.lang.Thread.run(Thread.java:724)
3.I 添加到 class 路径中,我的包启动了,但我得到了 class 未找到异常
java.lang.ClassNotFoundException: org.eclipse.kura.binding.enocean.EnOcean
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:340)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1212)
at org.eclipse.equinox.internal.ds.model.ServiceComponent.createInstance(ServiceComponent.java:493)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.createInstance(ServiceComponentProp.java:272)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:333)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
[1]https://github.com/dog-gateway/enj-library
如何将此库包含在我的 OSGI 包中?
非常感谢您的帮助!
enocean 库似乎是一个 OSGi 包。所以你应该把它添加到你的目标平台,并在你自己的包中使用 Import-Package 来访问你需要的包。