简体   繁体   English

OSGI套件:NoClassDefFoundError

[英]OSGI bundle: NoClassDefFoundError

I got this exception starting my bundle: 我在启动捆绑包时遇到了以下异常:

java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListener

My bundle is using this bundle:[1]enocean library the enocean library[1] is using the rxtx library that I added it as a bundle in my project, the rxtx contains the not found class: "SerialPortEventListener" 我的捆绑软件正在使用此捆绑软件:[1] enocean库,enocean库[1]使用的是我将其作为捆绑软件添加到我的项目中的rxtx库,rxtx包含未找到的类:“ SerialPortEventListener”

the EnOcean library[1] is declaring the package gnu.io as an imported package , and the bundle rxtx is exporting the package, the package version is the same. EnOcean库[1]将软件包gnu.io声明为已导入的软件包,并且捆绑包rxtx正在导出该软件包,该软件包的版本相同。

I found out that the error NoClassDefFoundError is lanched if the class depends of another class that can't be found, but the SerialPortEventListener is an interface inhiriting from EventListener. 我发现如果该类依赖于另一个找不到的类,则会出错NoClassDefFoundError,但是SerialPortEventListener是从EventListener继承的接口。

Can't find out why the equinox can't found it. 找不到为什么春分找不到它的原因。

!ENTRY org.eclipse.equinox.ds 4 0 2015-06-22 12:55:02.616
!MESSAGE [SCR] Exception while activating instance org.eclipse.kura.binding.enocean.EnOcean@79d49d of component org.eclipse.kura.binding.enocean
!STACK 0
java.lang.reflect.InvocationTargetException
        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.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:347)
        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)
Caused by: java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListener
        at org.eclipse.kura.binding.enocean.EnOcean.activate(EnOcean.java:27)
        ... 15 more
Caused by: java.lang.ClassNotFoundException: gnu.io.SerialPortEventListener
        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)
        ... 16 more
Root exception:
java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListener
        at org.eclipse.kura.binding.enocean.EnOcean.activate(EnOcean.java:27)
        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.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:347)
        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)
Caused by: java.lang.ClassNotFoundException: gnu.io.SerialPortEventListener
        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)
        ... 16 more

Updates: I tried a new approach, I copied the source file of the EnOcean library into my bundle, those sources uses the libary [2]Reflections 更新:我尝试了一种新方法,我将EnOcean库的源文件复制到了我的包中,这些源使用了库[2] Reflections

I warraped the library into a bundle (using eclipse: creating bundle from exiting archives) and I started it (the bundles starts with no error) 我将库整理成一个包(使用eclipse:从退出的档案创建包),然后启动了它(包开始时没有错误)

I imported the needed packages from the bundle Reflections but starting my bundle causes the same error but in the Reflections bundle 我从反射包中导入了所需的软件包,但是启动反射包时会导致相同的错误,但在反射包中

I started the bundle guava since it is the one causing the error but without success, I added the packages of the bundle guava[3] needed by the reflections as imported packages and again no success :( Here is the error: 我启动了软件包番石榴,因为它是导致错误的软件包,但是没有成功,我添加了反射所需的软件包番石榴[3]的软件包作为导入的软件包,再次失败了:(这是错误:

Root exception:
java.lang.NoClassDefFoundError: com/google/common/collect/Lists
        at org.reflections.util.FilterBuilder.<init>(FilterBuilder.java:24)
        at org.reflections.scanners.SubTypesScanner.<init>(SubTypesScanner.java:19)
        at org.reflections.scanners.SubTypesScanner.<init>(SubTypesScanner.java:12)
        at org.reflections.util.ConfigurationBuilder.<init>(ConfigurationBuilder.java:53)
        at EnOcean.EEP.EEPRegistry.<init>(EEPRegistry.java:26)
        at EnOcean.EEP.EEPRegistry.getInstance(EEPRegistry.java:53)
        at EnOceanLibrary.communication.EnJConnection.initCommon(EnJConnection.java:205)
        at EnOceanLibrary.communication.EnJConnection.<init>(EnJConnection.java:154)
        at org.eclipse.kura.binding.enocean.EnOcean.activate(EnOcean.java:31)
        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.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:347)
        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)

Thanks in advance for your help! 在此先感谢您的帮助!

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

[2] http://mvnrepository.com/artifact/org.reflections/reflections/0.9.9-RC2 [2] http://mvnrepository.com/artifact/org.reflections/reflections/0.9.9-RC2

[3] http://mvnrepository.com/artifact/com.google.guava/guava/15.0 [3] http://mvnrepository.com/artifact/com.google.guava/guava/15.0

The exception seems to be coming from the org.eclipse.kura.binding.enocean bundle, not from the EnJ-Library bundle. 异常似乎来自org.eclipse.kura.binding.enocean包,而不是来自EnJ-Library包。

Does org.eclipse.kura.binding.enocean import the package gnu.io ? org.eclipse.kura.binding.enocean是否导入软件包gnu.io

@Neil Barlett: Thanks for your response! @Neil Barlett:感谢您的回复!

Finally I added the reflections.jar in my libs directory and I added it in the Bundle class path. 最后,我在libs目录中添加了Reflections.jar,并将其添加到Bundle类路径中。 and I imported the com.google.common.collect in my bundle. 然后将com.google.common.collect导入了我的捆绑包。 and this time it worked, not sure if it is the best solution but it seems like when I wrap the reflections.jar in a bundle using eclipse it did not work properly. 这次它起作用了,不确定是否是最好的解决方案,但是当我使用eclipse将reflections.jar包装在一个包中时,它似乎无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM