Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Using JNI
Using JNI [message #1635126] Wed, 25 February 2015 16:32 Go to next message
Davide De Cesaris is currently offline Davide De CesarisFriend
Messages: 30
Registered: January 2015
Member
I need to use a C native library with Kura. I'm using an ARM cross compiler to build my library for that architecture and now I should specify in the Kura Bundle MANIFEST that I want to load that library at runtime. I used this:
Bundle-NativeCode: natives/my_library.so; osname=Linux; processor=ARM_le

but in this way I cannot export the Bundle (java.lang.Exception: Error while exporting project ...).

So, how can I use my native library with Kura?
Re: Using JNI [message #1635405 is a reply to message #1635126] Wed, 25 February 2015 19:43 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Your setup looks okay to me from what you have posted. Can you post the complete error?

Kura uses several native libraries, you can take a look at the serial bundle [1] to see how it is using selection filters. This bundle uses the maven bundle plugin, so the Manifest is defined the POM file.

[1] https://github.com/eclipse/kura/blob/develop/target-platform/org.eclipse.soda.dk.comm/pom.xml

Thanks,
--Dave
Re: Using JNI [message #1638989 is a reply to message #1635405] Fri, 27 February 2015 11:53 Go to previous messageGo to next message
Davide De Cesaris is currently offline Davide De CesarisFriend
Messages: 30
Registered: January 2015
Member
Hi Dave,

thanks for you reply. Inserting a trailing "*" in Bundle-NativeCode:
Bundle-NativeCode: natives/mylib.so; osname=Linux; processor=ARM, *

solved the issue with the bundle export. Anyway, in bundle activator, when I try to call the loadLibrary() method I receive this error:
java.lang.UnsatisfiedLinkError: no mylib in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
	at java.lang.Runtime.loadLibrary0(Runtime.java:849)
	at java.lang.System.loadLibrary(System.java:1087)
        ...

I read somewhere that it is unnecessary to specify java.library.path in the newer version of OSGi, is it true? In the pom.xml file of serial bundle [1], the maven plugin configures that variable:
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7.2</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.library.path>${project.basedir}/src/main/lib</java.library.path>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

If I should do the same, is there a way to specify the java.library.path in the MANIFEST?

[Updated on: Sat, 28 February 2015 08:56]

Report message to a moderator

Re: Using JNI [message #1640411 is a reply to message #1638989] Sat, 28 February 2015 03:52 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
I'm a little confused by the error. Your Manifest is specifying a library called "libjni_solair.so", but the error is referencing a library called "mylib". Can you post your System.loadLibrary() statement? Your statement should be System.loadLibrary("libjni_solair").

I am not sure about java.library.path being needed for newer versions of OSGi, I will need to check on that. The references you are seeing in Kura are for the maven-surefire-plugin. This is a plugin used for running tests, it shouldn't effect the normal operation of Kura. The Bundle-NativeCode in your Manifest is all you should need.

Thanks,
--Dave
Re: Using JNI [message #1640844 is a reply to message #1640411] Sat, 28 February 2015 08:56 Go to previous messageGo to next message
Davide De Cesaris is currently offline Davide De CesarisFriend
Messages: 30
Registered: January 2015
Member
Sorry Dave, I thought to had changed both names Smile
The library name is the same for the Manifest and the error, of course (I changed the previous message, now).
Re: Using JNI [message #1646372 is a reply to message #1640844] Tue, 03 March 2015 00:33 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hi Davide,

I was confused by your response. Is the library loading now or are you still having trouble? If you are still having issues, could you try loading the library in a very simple Java program? This would confirm there are no issues with the library itself.

Thanks,
--Dave
Re: Using JNI [message #1647058 is a reply to message #1646372] Tue, 03 March 2015 08:27 Go to previous messageGo to next message
Davide De Cesaris is currently offline Davide De CesarisFriend
Messages: 30
Registered: January 2015
Member
Hi Dave,

I'm still having trouble: the library is not loaded because it is not found in the java.library.path variable. If I try to use it with a POJO, there are no issues, so I think it's something related to OSGi configuration. If I can try something to help you understand the issue, let me know Wink
Re: Using JNI [message #1648267 is a reply to message #1647058] Tue, 03 March 2015 21:12 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
You may need to make sure you are correctly naming your library as defined here [1], or loading the complete file name. I tried the following three cases:

Case 1:
Created a library named libmyTest.so.
I defined the library in my manifest as:
Bundle-NativeCode: natives/libmyTest.so; osname=Linux; processor=ARM, *

I loaded the library with:
static {
    System.loadLibrary("myTest");
}


When I installed and started the bundle, the library worked fine.

Case 2:
Created a library named myTest.so.
I defined the library in my manifest as:
Bundle-NativeCode: natives/myTest.so; osname=Linux; processor=ARM, *

I loaded the library with:
static {
    System.loadLibrary("myTest");
}


When I installed and started the bundle, the library failed with the same error you are seeing.

Case 3:
Created a library named myTest.so.
I defined the library in my manifest as:
Bundle-NativeCode: natives/myTest.so; osname=Linux; processor=ARM, *

I loaded the library with:
static {
    System.loadLibrary("myTest.so");
}


When I installed and started the bundle, the library worked fine.

[1] http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Thanks,
--Dave
Re: Using JNI [message #1650042 is a reply to message #1648267] Wed, 04 March 2015 16:35 Go to previous messageGo to next message
Davide De Cesaris is currently offline Davide De CesarisFriend
Messages: 30
Registered: January 2015
Member
Sorry Dave, it was my fault with the library name Rolling Eyes

Now, the library is loaded, but there is another issue:
Root exception:
java.lang.UnsatisfiedLinkError: /tmp/.kura/configuration/org.eclipse.osgi/bundles/109/1/.cp/natives/libTest.so: /tmp/.kura/configuration/org.eclipse.osgi/bundles/109/1/.cp/natives/libTest.so: cannot open shared object file: No such file or directory


If I check in the error path, the library is there, but it is not executable (while the same is executable before the plugin export in my laptop). Do you know what is wrong now?
Re: Using JNI [message #1650792 is a reply to message #1650042] Thu, 05 March 2015 01:31 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
I have not seen that one. I would try a couple of things.

1. If you haven't, reboot the RPi.
2. Stop Kura, delete the /tmp/.kura directory, restart Kura.

If those don't help, would it be possible to post the library somewhere (ex: Github) so I could download it and try it?

Thanks,
--Dave
Re: Using JNI [message #1653496 is a reply to message #1650792] Fri, 06 March 2015 08:46 Go to previous message
Davide De Cesaris is currently offline Davide De CesarisFriend
Messages: 30
Registered: January 2015
Member
Hi Dave,

after a while I realised it was an issue with the library compiled for the ARM architecture. I tried to re-compile with Linaro cross-compiler and now it works fine. Sorry for my mistake and thanks a lot for your help.
Previous Topic:JUnit Tests with Kura
Next Topic:MeshedPi - IoT Long Range Swarm
Goto Forum:
  


Current Time: Fri Apr 26 10:58:25 GMT 2024

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

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

Back to the top