title: Loading native libraries in java
body: <p>I have an eclipse project with two classes. The class "SomeClass1" has a native method:</p>
  
  <p><strong>SomeClass1</strong></p>
  
  <pre><code>public class SomeClass1 {
      static {
          System.loadLibrary("libname"); // Load the native library.
      }
      public native void some_method(); // implemented in the library
      // .... other non methods ....
  }
  </code></pre>
  
  <p>The other class "SomeClass2" uses the native method of "SomeClass1". Like:</p>
  
  <p><strong>SomeClass2</strong></p>
  
  <pre><code>public class SomeClass2{
      public static void main(String[] args) {
          SomeClass1 s = new SomeClass1();
          s.some_method();
      }
      // ....other methods....
  }
  </code></pre>
  
  <p>However when it calls that method it throws an error like this:</p>
  
  <pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: no libname in java.library.path
  ....
  at java.lang.System.loadLibrary(Unknown Source)
  at x.x.x.SomeClass1.&lt;clinit&gt;(SomeClass1.java:128)
  at SomeClass2.main(SomeClass2.java:10)
  </code></pre>
  
  <p>I think the error has something to do with java not knowing where to look for the native  library. </p>
  
  <p><strong>Question1</strong>
  When I use: -Djava.library.path="C:\Users.....\libfolder\" as run argument in eclipse and print the value of: System.getProperty("java.library.path"); I see alot of directories printed but not the directory that I specified in the argument. What am I doing wrong?</p>
  
  <p><strong>Question2</strong>
  When I do: System.loadLibrary("name"); do I need to call the library "name.so" or "libname.so"?</p>
  
  <p><strong>Question3</strong>
  If the library would be found but was a 64 bit library while the platform it is loaded on is 32 bit, would it also give a unsatisfiedLinkError or would a different error be given?</p>
  
  <p><strong>Question4</strong>
  Can I specify the path to the library relative to the projects folder or relative to the file in which the library is loaded?</p>
  
  <p>Hope you are able to answer (some of) my questions.</p>
  
  <p>Grtz Stefan</p>