How to add .so file to the java.library.path in Linux

Add the containing directory to LD_LIBRARY_PATH before launching the application

        export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/some/pathOfContainingDirectory

Use java -XshowSettings:properties to show the java.library.path (and others) value.


I had a lot of trouble figuring this out, please make sure that you have lib prefix in the library name.

So steps,

  1. export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/some/pathOfContainingDirectory"

  2. Rename libraries to have lib as a prefix. [Add this as part of build script]

    mv JNIDemo.so libJNIDemo.so
    

Check this answer for detailed explanation https://stackoverflow.com/a/3987567/2076566


I used java -XshowSettings:properties method and found the path of a previously set folder and copied my so file to that folder