title: Setting Java Classpath to Load a Class File
body: <p>I'm new to Java, and I'm unsure how to access a class file located in a specific directory from a separate program jar.</p>
  
  <p>For example, I have an third party jar file located in /, which is supposed to load MyClass located in /mylib/MyClass.class, so I tried running:</p>
  
  <pre><code>java -jar mainprog.jar -classpath "/mylib" MyClass
  </code></pre>
  
  <p>but I'm getting the error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: MyClass
  Caused by: java.lang.ClassNotFoundException: MyClass
          at java.net.URLClassLoader$1.run(URLClassLoader.java:221)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:209)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:324)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:269)
          at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:337)
  </code></pre>
  
  <p>What am I doing wrong?</p>