title: Java JNI: Specify path to dependent shared library
body: <p>I built a JNI library <code>libmyjni.dylib</code> and it is linked with <code>libthirdparty.dylib</code>. While starting my Java application, I set <code>-Djava.library.path=/path/to/native/libs</code> but that path is not being used to load <code>libthirdparty.dylib</code>. Java is always looking for <code>libthirdparty.dylib</code> under <code>&lt;project_root&gt;/lib</code> folder. What parameter do I set so as to look for <code>libthirdparty.dylib</code> in the same path as <code>java.library.path</code>?</p>
  
  <p>This is the error I get if I don't put <code>libthirdparty.dylib</code> under <code>&lt;project_root&gt;/lib</code>. I also tried creating <code>/etc/ld.so.conf</code> with path to <code>libthirdparty.dylib</code> in int but that did not help as well.</p>
  
  <pre><code>java.lang.UnsatisfiedLinkError: &lt;java_library_path&gt;/libmyjni.dylib: dlopen(&lt;java_library_path&gt;/libmyjni.dylib, 1): Library not loaded: lib/libthirdparty.dylib
    Referenced from: &lt;java_library_path&gt;/libmyjni.dylib
    Reason: image not found
  </code></pre>