title: Loading jars at runtime
body: <p>I am trying to add jar file to classpath at runtime. I use this code</p>
  
  <pre><code> public static void addURL(URL u) throws IOException {
  
              URLClassLoader sysloader = (URLClassLoader) ClassLoader
                      .getSystemClassLoader();
              Class&lt;URLClassLoader&gt; sysclass = URLClassLoader.class;
  
              try {
                  Method method = sysclass.getDeclaredMethod("addURL", parameters);
                  method.setAccessible(true);
                  method.invoke(sysloader, new Object[] { u });
                  System.out.println(u);
              } catch (Throwable t) {
                  t.printStackTrace();
                  throw new IOException("Error");
              }
  
          }
  </code></pre>
  
  <p>System out prints this url:</p>
  
  <pre><code>file:/B:/Java/Tools/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar
  </code></pre>
  
  <p>I was check this path carefully, this jar exist. Even this test show that com.mysql.jdbc.
  Driver class exists.</p>
  
  <pre><code>javap -classpath "B:\Java\Tools\mysql-connector-java-5.1.18\
  mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar" com.mysql.jdbc.
  Driver
  Compiled from "Driver.java"
  public class com.mysql.jdbc.Driver extends com.mysql.jdbc.NonRegisteringDriver i
  mplements java.sql.Driver{
      public com.mysql.jdbc.Driver()       throws java.sql.SQLException;
      static {};
  }
  </code></pre>
  
  <p>But I still get java.lang.ClassNotFoundException when I use this Class.forName(driver).
  What is wrong with this code?</p>