I am using Eclipse Java and Eclipse C/C++ on OSX Yosemite to create a simple Java JNI application. Here are the steps I performed
- Wrote a class on Java Eclipse with native method.
- Using this class, created a C header file using
javah
executable and included the the header file in Eclipse C/C++. On building the C code, .so file is created. - Then I added the path to .so file using eclipse (Run/Run Configutations/Java Application/Environment) by setting variable name as PATH and value as
%PATH%/Users/XXXX/Documents/JniWorkspace/JniExampleLibrary/Debug
Here is Java code to load the C library:
public class JniExample {
static {
System.loadLibrary("JniExampleLibrary");
}
public native void callNativeMethod();
....
....
}
But still I am getting the error as shown below:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no JniExampleLibrary 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) at code.example.JniExample.(JniExample.java:5) at code.example.Main.main(Main.java:8)