title: java unable to find native libraries on java.library.path
body: <p>So I am trying to run a very simple java program that uses IBM CPLEX on a mac. The program recognizes the JAR file but cannot seem to find the native implementations no matter where I point to it.</p>
  <p>The Java Program:</p>
  <pre class="lang-java prettyprint-override"><code>import ilog.cplex.IloCplex;
  
  public class CPLEXTester {
      public static void main(String[] args) {
          System.out.println(System.getProperty(&quot;java.library.path&quot;));
          try {
              new IloCplex();
          }
          catch(Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>Output in intellij:</p>
  <pre><code>/Users/bradley/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1/Contents/Home/bin/java -Dvisualvm.id=27090629736541 -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=63865:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/bradley/Desktop/code/cplexTester/out/production/cplexTester:/Users/bradley/Desktop/code/adaje/code/lib/java/cplex-12.9.jar CPLEXTester
  /Users/bradley/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
  java.lang.UnsatisfiedLinkError: no cplex1290 in java.library.path: /Users/bradley/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
  java.library.path must point to the directory containing the CPLEX shared library
  try invoking java with java -Djava.library.path=...
  Exception in thread &quot;main&quot; java.lang.UnsatisfiedLinkError: 'long ilog.cplex.Cplex.CPXopenCPLEX(int[])'
      at ilog.cplex.Cplex.CPXopenCPLEX(Native Method)
      at ilog.cplex.CplexI.init(CplexI.java:7083)
      at ilog.cplex.CplexI.&lt;init&gt;(CplexI.java:856)
      at ilog.cplex.IloCplex.&lt;init&gt;(IloCplex.java:12042)
      at ilog.cplex.IloCplex.&lt;init&gt;(IloCplex.java:12057)
      at CPLEXTester.main(CPLEXTester.java:7)
  </code></pre>
  <p>The CPLEX native library location I am trying to use is /Library/Java/Extensions. As can be seen below I have both libcplex1290.jnilib as well as libcplex1290.dylib in the directory:
  <a href="https://i.stack.imgur.com/GTOJb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GTOJb.png" alt="/Library/Java/Extensions listed" /></a></p>
  <p>Java just keeps throwing UnsatisfiedLinkError(s). When I explicitly try to link and run the below command in zsh I get the same output:</p>
  <pre><code>java -Djava.library.path=/Library/Java/Extensions -cp ~/Desktop/code/lib/java/cplex-12.9.jar CPLEXTester.java
  </code></pre>
  <p>Another interesting note is that when I try to load the library i.e.:</p>
  <pre class="lang-java prettyprint-override"><code>public class CPLEXTester {
      public static void main(String[] args) {
          System.load(&quot;/Library/Java/Extensions/libcplex1290.jnilib&quot;);
      }
  }
  </code></pre>
  <p>I get another UnsatisfiedLinkError:</p>
  <pre><code>/Users/bradley/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1/Contents/Home/bin/java -Dvisualvm.id=27158373972541 -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=63876:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/bradley/Desktop/code/cplexTester/out/production/cplexTester:/Users/bradley/Desktop/code/adaje/code/lib/java/cplex-12.9.jar CPLEXTester
  Exception in thread &quot;main&quot; java.lang.UnsatisfiedLinkError: Can't load library: /Library/Java/Extensions/libcplex1290.jnilib
      at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2398)
      at java.base/java.lang.Runtime.load0(Runtime.java:785)
      at java.base/java.lang.System.load(System.java:1979)
      at CPLEXTester.main(CPLEXTester.java:5)
  </code></pre>
  <p>Does anyone have any ideas on how this can be resolved? Thank you in advance!</p>
  <p>This is my 'About This Mac':</p>
  <p><a href="https://i.stack.imgur.com/tQAI4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tQAI4.png" alt="About my mac" /></a></p>
  <p>Java base settings:</p>
  <pre><code>java -XshowSettings:properties -version
  Property settings:
      file.encoding = UTF-8
      file.separator = /
      ftp.nonProxyHosts = local|*.local|169.254/16|*.169.254/16
      http.nonProxyHosts = local|*.local|169.254/16|*.169.254/16
      java.class.path = 
      java.class.version = 62.0
      java.home = /Users/bradley/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1/Contents/Home
      java.io.tmpdir = /var/folders/6w/qsmx4xpn7vs528v_7qvm_k9m0000gq/T/
      java.library.path = /Users/bradley/Library/Java/Extensions
          /Library/Java/Extensions
          /Network/Library/Java/Extensions
          /System/Library/Java/Extensions
          /usr/lib/java
          .
      java.runtime.name = OpenJDK Runtime Environment
      java.runtime.version = 18.0.1.1+2-6
      java.specification.name = Java Platform API Specification
      java.specification.vendor = Oracle Corporation
      java.specification.version = 18
      java.vendor = Oracle Corporation
      java.vendor.url = https://java.oracle.com/
      java.vendor.url.bug = https://bugreport.java.com/bugreport/
      java.version = 18.0.1.1
      java.version.date = 2022-04-22
      java.vm.compressedOopsMode = Zero based
      java.vm.info = mixed mode, sharing
      java.vm.name = OpenJDK 64-Bit Server VM
      java.vm.specification.name = Java Virtual Machine Specification
      java.vm.specification.vendor = Oracle Corporation
      java.vm.specification.version = 18
      java.vm.vendor = Oracle Corporation
      java.vm.version = 18.0.1.1+2-6
      jdk.debug = release
      line.separator = \n 
      native.encoding = UTF-8
      os.arch = aarch64
      os.name = Mac OS X
      os.version = 12.4
      path.separator = :
      socksNonProxyHosts = local|*.local|169.254/16|*.169.254/16
      sun.arch.data.model = 64
      sun.boot.library.path = /Users/bradley/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1/Contents/Home/lib
      sun.cpu.endian = little
      sun.io.unicode.encoding = UnicodeBig
      sun.java.launcher = SUN_STANDARD
      sun.jnu.encoding = UTF-8
      sun.management.compiler = HotSpot 64-Bit Tiered Compilers
      sun.stderr.encoding = UTF-8
      sun.stdout.encoding = UTF-8
      user.country = US
      user.dir = /Users/bradley
      user.home = /Users/bradley
      user.language = en
      user.name = bradley
  
  openjdk version &quot;18.0.1.1&quot; 2022-04-22
  OpenJDK Runtime Environment (build 18.0.1.1+2-6)
  OpenJDK 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)
  </code></pre>