在OSGI包中使用外部Java库

w6lpcovy  于 2023-11-15  发布在  Java
关注(0)|答案(2)|浏览(118)

我想在我的OSGI包中使用这个java库[1]enj-library,它将在KURA eclipse平台下执行。
我将库编译为jar,然后在eclipse下创建了一个新的插件项目“Plug-in from existing Eclipse archive”
然后我试图将其添加到我的bundle中,但它不起作用:1.我试图导入bundle,我验证了导入和导出的清单文件中的版本是正确的,但我gopt这个错误:

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.我把它作为一个必需的捆绑包,但我得到了同样的错误:

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.我添加了类路径,我的包开始了,但我得到了类找不到异常

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](https://github.com/dog-gateway/enj-library)
如何将这个库包含在我OSGI包中?
非常感谢你的帮助!

gkn4icbw

gkn4icbw1#

enocean库似乎是一个OSGi包。所以你应该将它添加到你的目标平台,并在你自己的包中使用Import-Package来访问你需要的包。

jfgube3f

jfgube3f2#

配置中还有一个方便的“org.osgi.framework.system.packages.extra”属性,这个逗号分隔的列表将允许系统类加载器中的命名包出现在系统包中,从而可以访问插件。
如果您使用apache fashion,请查看https://felix.apache.org/documentation/subprojects/apache-felix-framework/apache-felix-framework-configuration-properties.html
另一个很棒的页面是:https://moi.vonos.net/java/osgi-classloaders/真的很技术,但给出了一个很好的理解OSGi类加载过程

相关问题