Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Using an external java library in OSGI bundle
Using an external java library in OSGI bundle [message #1698864] Thu, 18 June 2015 13:04 Go to next message
Sabrina anirbas is currently offline Sabrina anirbasFriend
Messages: 45
Registered: April 2015
Member
Hello,

I want to use this java library in my OSGI bundle that will be executed under KURA :
https://github.com/dog-gateway/enj-library

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 got 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)


how can I include this library on my OSGI bundle?

Thanks a lot for your help!
Re: Using an external java library in OSGI bundle [message #1698925 is a reply to message #1698864] Thu, 18 June 2015 21:42 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

It looks as though the project you referenced is already setup to generate an OSGi bundle. When you created the jar file, did you do so by using the provided Maven POM file? If so, the created jar file is an OSGi bundle. You can install that file on your Kura device through the OSGi console [1]. If you need more information on this let me know.

Once that bundle is running, you can simply import the desired packages in your bundle's MANIFEST.MF. For development, you would need to either add the complete project to your workspace or add the created bundle to the target-definition. Again, if you need more information on how to do this, let me know.

[1] http://eclipse.github.io/kura/doc/deploying-bundles.html

--Dave
Re: Using an external java library in OSGI bundle [message #1698964 is a reply to message #1698925] Fri, 19 June 2015 08:10 Go to previous messageGo to next message
Sabrina anirbas is currently offline Sabrina anirbasFriend
Messages: 45
Registered: April 2015
Member
Hi,

Thanks for your reponse!
Seems that the EnOcean bundle needs another dependency with the package "gnu.io version 0.0.0" which can be provided by rxtx java library
So I tryied to follow this link to wrap up the java library into a bundle:

http://rxtx.qbang.org/wiki/index.php/Wrapping_RXTX_in_an_Eclipse_Plugin

but still can't start it on kura Sad
I got this error:

Bundle cannot be started: Error[message=Failed to start bundle: The bundle "RXTX_Bundle_1.0.0 [78]" could not be resolved. Reason: No match found for native code: nativelib/librxtxSerial.so; processor=armv6l; osname=Linux;details=null]
!STACK 0
org.osgi.framework.BundleException: The bundle "RXTX_Bundle_1.0.0 [78]" could not be resolved. Reason: No match found for native code: nativelib/librxtxSerial.so; processor=armv6l; osname=Linux
        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.GeneratedMethodAccessor22.invoke(Unknown Source)
        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)


I am running KURA on my Raspberry pi, so my OS is linux and my architecture is ARM and I add this on my rxtx bundle manifest:

Bundle-NativeCode: /usr/lib/jni/librxtxSerial.so;osname="Linux";processor="armv6l"

[Updated on: Fri, 19 June 2015 11:42]

Report message to a moderator

Re: Using an external java library in OSGI bundle [message #1699034 is a reply to message #1698964] Fri, 19 June 2015 16:19 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

First, you want to place the native library for your Raspberry Pi in your bundle, not on the system itself. Move the native library to your RXTX project. Then, if you have a path in your bundle called "nativelib/rpi/librxtxSerial.so", your Manifest would look like:

Bundle-NativeCode: nativelib/rpi/librxtxSerial.so


Second, I am not sure "armv6l" is a valid tag. Have a look at a list of valid tags and aliases [1]. In Kura, we typically use "ARM" for the Raspberry Pi and use custom properties to switch between different architectures. You can have a look at how we do native library loading here [2].

[1] http://www.osgi.org/Specifications/Reference#processor
[2] https://github.com/eclipse/kura/blob/develop/target-platform/javax.usb.linux/pom.xml

--Dave


Re: Using an external java library in OSGI bundle [message #1699196 is a reply to message #1699034] Mon, 22 June 2015 13:24 Go to previous messageGo to next message
Sabrina anirbas is currently offline Sabrina anirbasFriend
Messages: 45
Registered: April 2015
Member
Hello,

Thanks for your response! The bundle rxtx is running!
I placed the native library into my project and I update the tag to "ARM"

But I got a new error in kura-console.log, when I start my bundle that uses the EnOcean library:
seems that equinox still can't find the class gnu.io.SerialPortEventListener that is provided by the bundle rxtx,
the EnOcean library is declaring the package gnu.io as an imported package , and the bundle rxtx is exporting the package, the package version is the same
can't find why it can't find it Sad

!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



Re: Using an external java library in OSGI bundle [message #1699235 is a reply to message #1699196] Mon, 22 June 2015 20:43 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

It is hard to say without seeing the source code, but is your bundle trying to use gnu.io.SerialPortEventListener directly? If so, your bundle would need to import gnu.io. If not, it may be necessary to post your activation code.

It may be worth while to build a simple stand alone Java application that uses enOcean and your native library. This would ensure your application is working correctly outside of an OSGi container.

Thanks,
--Dave
Re: Using an external java library in OSGI bundle [message #1699490 is a reply to message #1699235] Wed, 24 June 2015 14:58 Go to previous message
Sabrina anirbas is currently offline Sabrina anirbasFriend
Messages: 45
Registered: April 2015
Member
Hello,

I followed another approach I added the EnOcean library code source in my bundle and I imported my bundle rxtx and it worked!
seems like the EnOcean bundle is using an embedded rxtx.jar file and may that is way it can't see my bundle rxtx.

Thanks!
Previous Topic:Kura and EnOcean technology
Next Topic:Bluetooth SPP Implementation
Goto Forum:
  


Current Time: Thu Apr 25 05:23:22 GMT 2024

Powered by FUDForum. Page generated in 0.03320 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top