Reputation: 35
I have a C project. I compiled it as a library (.so), and I use JNI to import it into a java project. Everything is going well. But I want to compile it into a .jar file, so I can distribute it and the user won't have to create the Java Class implementing the C functions (with JNI). So I tried to do that, but when I try to compile again (in a clean project, with the .jar containing the class and the .so) the class (from the jar) doesn't find the .so anymore, the symbols are not recognized. I don't want the user to manually link the .so to the jar (in Eclipse or whatever).
I don't have much experience with java or eclipse so I am quite lost.
Does anyone have an answer or something to help me?
Upvotes: 0
Views: 181
Reputation: 111279
The dynamic linker on most operating systems will not load libraries from a compressed archive; you have to extract the .so to a file to load it, for example in the directory for temporary files.
After that you'll have to use System.load to load the .so because it will not be in the library search path.
An alternative to this hassle is distributing the application using jnlp: the web start app will download, set up and run your application and you don't have to worry about extracting anything yourself. Native librariesare added with the nativelib
element. http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/syntax.html
Upvotes: 1