title: MySQL driver class not found, even when included in classpath
body: <p>I have the following code:</p>
  
  <h2>mypackage\Launcher.java:</h2>
  
  <pre><code>package mypackage;
  
  import mypackage.MainClass;
  
  public class Launcher
  {
      public static void main(String[] args)
      {
          new MainClass(args);
      }
  }
  </code></pre>
  
  <h2>mypackage\MainClass.java:</h2>
  
  <pre><code>package mypackage;
  
  import java.sql.*;
  import com.mysql.jdbc.Driver;
  
  public class MainClass
  {
      public MainClass(String[] args)
      {
          try
          {
              Class.forName("com.mysql.jdbc.Driver").newInstance();
          }
          catch (Exception ex)
          {
              System.err.println("Error: unable to load sql driver class!");
              ex.printStackTrace(System.err);
              System.exit(1);
          }
  
          System.out.println("We got here... How???");
      }
  }
  </code></pre>
  
  <p>The code compiles with no complaints using</p>
  
  <pre><code>javac -cp src;bin;lib\mysql-connector-java-5.1.38-bin.jar -sourcepath src -d bin src\mypackage\Launcher.java
  jar cfe myjar.jar mypackage.Launcher .
  </code></pre>
  
  <p>but when running </p>
  
  <pre><code>java -cp .\mysql-connector-java-5.1.38-bin.jar -jar myjar.jar
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Error: unable to load sql driver class!
  java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
          at java.net.URLClassLoader.findClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Unknown Source)
          at mypackage.MainClass.&lt;init&gt;(MainClass.java:10)
          at mypackage.Launcher.main(Launcher.java:9)
  </code></pre>
  
  <p></p>
  
  <p>I don't understand what I am missing here, and I have spent over 6 hours attempting to debug and searching for answers, but I have not found <em>anything</em> that has helped (pretty much everything I've found says "include the jarfile containing the class on the classpath &ndash; but I've very clearly done <em>just that</em>).</p>
  
  <p>What's going on?</p>