Exception in thread "main" java.lang.UnsatisfiedLinkError (Library not found despite being in java.lang.path)
<p>I am working on a 64bit Linux machine. I am trying to emulate a simple JNI tutorial given <a href="http://www.ibm.com/developerworks/java/tutorials/j-jni/j-jni.html" rel="nofollow noreferrer">here</a>. After I have prepared all the files, i.e. <code>Sample1.java, Sample1.class, Sample1.h, Sample1.cpp</code> and <code>libSample1.so</code>, and when I try to run the command</p>

<pre><code>java Sample1
</code></pre>

<p>I get the following error.</p>

<pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: no libSample1 in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
        at java.lang.Runtime.loadLibrary0(Runtime.java:849)
        at java.lang.System.loadLibrary(System.java:1088)
        at Sample1.main(Sample1.java:10)
</code></pre>

<p>The problem line of <code>Sample1.java</code> is given as;</p>

<pre><code>System.loadLibrary("libSample1");
</code></pre>

<p>I have read a question similar to mine <a href="https://stackoverflow.com/q/9905420/842808">here</a> and tried to take advice from one of its <a href="https://stackoverflow.com/a/9905495/842808">answers</a>, i.e. added current directory to environment variable <code>$LD_LIBRARY_PATH</code> (current directory contains <code>libSample1.so</code> file) using;</p>

<pre><code>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
</code></pre>

<p>But this still doesn't help me. Even a call to <code>java -XshowSettings:properties</code> shows that <code>java.library.path</code> contains <code>.</code> as one of the search paths.</p>

<p>When I replace relative file path with absolute file path by replacing <code>System.loadLibrary("libSample1")</code> with <code>System.load("&lt;absolute-file-path&gt;/libSample1.so");</code>, this problem goes away. Can someone tell me how to make sure that <code>java.library.path</code> can find my shared library file?</p>