When we were developing the JNI example as mentioned in our another post, “Java Native Interface ( JNI ) Example , Calling Native C functions from JAVA” we got an error “Exception in thread “main” java.lang.UnsatisfiedLinkError: no hello in java.library.path” as below,
Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1124) at HelloWorld.<clinit>(HelloWorld.java:4) at Main.main(Main.java:4)
This error can be solved by adding the PATH of the native shared library using LD_LIBRARY_PATH as,
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD
execute this command from the directory where you are trying to execute the JNI example. i.e. the directory where you have created shared library OR you can replace $PWD with the complete path to directory with shared library.
Now we can check the LD_LIBRARY_PATH as,
$ echo $LD_LIBRARY_PATH :/home/devlab/Desktop/jni
Now, if you execute the JNI application, you will not see the error.