title: Why doesn't java honour the class path when executing a jar file with the -jar switch?
body: <p>This works:</p>
  
  <pre><code>$ java -cp ".:/PATH/TO/RXTXcomm.jar:./jobexftp.jar" -Djava.library.path=/usr/lib/jni com.lhf.jobexftp.StandAloneApp
  JObexFTP 2.0 beta (15/10/2010)
  Java Obex File Transfer Protocol application and library
  Developed under/using 100% free software.
  For more information access: http://www.lhf.ind.br/jobexftp/
  
  Usage: jobexftp &lt;serialPort&gt; [&lt;commands&gt;] [&lt;options&gt;]
  ...
  </code></pre>
  
  <p>This doesn't:</p>
  
  <pre><code>$ java -cp ".:/PATH/TO/RXTXcomm.jar" -Djava.library.path=/usr/lib/jni -jar jobexftp.jar
  Error: A JNI error has occurred, please check your installation and try again
  Exception in thread "main" java.lang.NoClassDefFoundError: gnu/io/NoSuchPortException
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
      at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
  </code></pre>
  
  <p>I found the class name to execute (for the first example) in the META-INF/MANIFEST.MF file, inside the jar:</p>
  
  <pre><code>Main-Class: com.lhf.jobexftp.StandAloneApp
  </code></pre>
  
  <p>Why does executing the jar file, with the -jar switch seem to cause Java to ignore the classpath and fail to find the <code>gnu/io/NoSuchPortException</code> class in RXTXcomm.jar?</p>
  
  <hr>
  
  <p>On an older machine, running Java 1.6, I can execute the jar file without needing a classpath.  How does this work?</p>
  
  <pre><code>$ env | grep CLASS
  $ env | grep JAVA
  $ java -jar jobexftp.jar 
  JObexFTP 2.0 beta (15/10/2010)
  Java Obex File Transfer Protocol application and library
  Developed under/using 100% free software.
  For more information access: http://www.lhf.ind.br/jobexftp/
  
  Usage: jobexftp &lt;serialPort&gt; [&lt;commands&gt;] [&lt;options&gt;]
  ...
  </code></pre>
  
  <hr>
  
  <p>The reason it worked on the old machine is that it had a copy of RXTXcomm.jar in /usr/lib/jvm/java-6-sun-1.6.0.21/jre/lib/ext/.</p>
  
  <pre><code>$ ls -lA /usr/lib/jvm/java-6-sun-1.6.0.21/jre/lib/ext/RXTXcomm.jar
  -rwxr-xr-x 1 root root 137764 2011-02-17 16:58 /usr/lib/jvm/java-6-sun-1.6.0.21/jre/lib/ext/RXTXcomm.jar
  </code></pre>
  
  <p>Making a new <code>ext</code> directory in /usr/lib/jvm/java-8-oracle/jre and copying <code>RXTXcomm.jar</code> into it <em>doesn't</em> get rid of the error on Java 1.8. </p>