title: Java, Load native library inside classpath
body: <p>I have the following distribution</p>
  
  <pre><code>.__bin
  |   |__start.sh
  |
  |__lib
      |__Main.jar
      |__Utility.jar
      |__lib.so
  </code></pre>
  
  <p><em>Main.jar</em> contains main method, in which I would like to access native functions provided by the <em>lib.so</em> bundled in the distribution. <em>start.sh</em> simply sets the classpath and bootstraps java.</p>
  
  <p>What is the best approach to load the <em>lib.so</em> library inside the application? I am aware of two methods:</p>
  
  <ul>
  <li>System.load(<em>absolute path</em>)</li>
  <li>System.loadLibrary(<em>name</em>)</li>
  </ul>
  
  <p>Former requires the absolute path of the library in the file system, latter requires setting the application specific <em>java.library.path</em> JVM argument. Which is better solution in this case? Would setting the library path in the <em>start.sh</em> script possibly break something? How could I get the absolute file system path of the library for the former solution?</p>