在OSGI包中使用外部java库 [英] Using an external java library in OSGI bundle

查看:188
本文介绍了在OSGI包中使用外部java库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的OSGI包中使用这个java库[1] enj-library,这个库将在KURA eclipse平台下执行。



我将库编译成jar然后我在eclipse现有JAR存档的插件下创建了一个新的插件项目,



然后我尝试将其添加到我的包中,但它没有工作:
1.我尝试导入捆绑包,并验证导入和导出中的两个清单文件中的版本是否正确,但是我出现了这个错误:

  org.osgi.framework.BundleException:包org.eclipse.kura.binding.enocean_1.0.0.201506181418 [70]无法解决。原因:缺少约束:Import-Package:it.polito.elite.enocean.enj.communication; version =1.0.0
在org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
在org.eclipse.osgi.framework.internal.core .AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
在org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
在org.eclipse.osgi.framework .internal.core.AbstractBundle.start(AbstractBundle.java:300)
在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)
在java.lang.reflect.Method.invoke(Method.java:606)
在org.tigris.mtoolkit.iagent.internal.pmp.InvocationThread.run(InvocationThread.java:54)
在org .tigris.mtoolkit.iagent.internal.utils.ThreadPool $ Worker.run(ThreadPool.java:179)
在java.lang.Thread.run(Thread.java:724)

2.我将其添加为必需的包,但我收到相同的错误:

  org.osgi.framework.BundleException:捆绑包org.eclipse.kura.binding.enocean_1.0.0.201506181349 [70]无法解决。原因:缺少约束:需求包:EnOceanJavaLibraryplugIn; bundle-version =1.0.0
在org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
在org.eclipse.osgi.framework.internal .core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
在org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
在org.eclipse.osgi .framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
在org.tigris.mtoolkit.iagent.internal.rpc.RemoteBundleAdminImpl.startBundle(RemoteBundleAdminImpl.java:230)
在太阳.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:606)
在org.tigris.mtoolkit.iagent.internal.pmp.InvocationThread.run(InvocationThread.java:54)
在org.tigris.mtoolkit.iagent.internal.utils.ThreadPool $ Worker.run(ThreadPool.java:179)
在java.lang.Thread.run(Thread.java:724)

3.我添加在类路径中,我的包开始,但我找到了类没有找到异常

  java.lang.ClassNotFoundException:org.eclipse.kura.binding.enocean.EnOcean 
在org.eclipse.osgi.internal.loader.BundleLoader .findClassInternal(BundleLoader.java:501)
在org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
在org.eclipse.osgi.internal.loader.BundleLoader .findClass(BundleLoader.java:412)
在org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
在java.lang.ClassLoader.loadClass(ClassLoader.java :357)
在org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:340)
在org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost的.java :229)
在org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1212)
在org.eclipse.equinox.internal.ds.model.ServiceComponent.createInstance (ServiceComponent.java:493)
在org.eclipse.equinox.internal.ds.model.ServiceComponentProp.createInstance(ServiceComponentProp.java:272)
在org.eclipse.equinox.internal.ds.model .ServiceComponentProp.build(ServiceComponentProp.java:333)
在org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
在org.eclipse.equinox.internal.ds .InstanceProcess.buildComponents(InstanceProcess.java:197)
在org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
在org.eclipse.equinox.internal.ds .Resolver.enableComponents(Resolver.java:217)
在org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
在org.eclipse.equinox.internal.ds .SCRManager $ QueuedJob.dispatch(SCRManager .java:783)
在org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
在org.eclipse.equinox.internal.util.impl.tpt.threadpool .Executor.run(Executor.java:70)

[1] https://github.com/dog-gateway/enj-library



/ p>

非常感谢您的帮助!

解决方案

enocean图书馆似乎是一个OSGi软件包。因此,您应该将其添加到目标平台,并使用自己的软件包中的Import-Package来访问所需的软件包。


I want to use this java library [1]enj-library in my OSGI bundle that will be executed under KURA eclipse platform.

I compiled the library as jar and then I created a new plugin project under eclipse "Plug-in from existing JAR archive"

then I tried to add it to my bundle, but it did not work: 1.I tried to import the bundle and I verified that the version is correct in both manifest files in the import and the export, but I gopt this error:

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 added it as a required bundle but the I got the same error:

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 added in the class path and my bundle started but I got the class not found exception

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

how can I include this library on my OSGI bundle?

Thanks a lot for your help!

解决方案

The enocean library seems to be an OSGi bundle. So you should add it to your target platform and use Import-Package in your own bundle to access the packages you need.

这篇关于在OSGI包中使用外部java库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆