title: java.lang.NoClassDefFoundError, but I successfully created instance of this class
body: <p>I'm trying to write launcher for one "game" that using LWJGL and I needed to load its classes from other JARs.</p>
  
  <p>So I did the following:</p>
  
  <pre><code>// ...
  
  // The files that i must load.
  String[] files = new String[] { "lwjgl.jar", "jinput.jar", "lwjgl_util.jar", "game_jar.jar" }; 
  
  // Converting strings to URLs
  urls = new URL[files.length];
   for ( int i = 0; i &lt; files.length; i++ )
    urls[i] = new File(directoryWithMyJARsAsFileClass, files[i]).toURI().toURL();
  
  // I'ts needed too
  System.setProperty("org.lwjgl.librarypath", directoryWithMyLWJGLNativessAsFileClass.getAbsolutePath() + File.separator);
  System.setProperty("net.java.games.input.librarypath", directoryWithMyLWJGLNativessAsFileClass.getAbsolutePath() + File.separator);
  
  // All paths are correct, I tested it.
  
  // Class loading
  URLClassLoader loader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader())
  // Object test = loader.loadClass("org.lwjgl.LWJGLException").newInstance(); // (2)
  Object game = loader.loadClass("the.game.package.MainClass").newInstance(); // (1)
  
  // ...
  </code></pre>
  
  <p>But code crashes on (1) with error: </p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
      at java.lang.Class.getConstructor0(Unknown Source)
      at java.lang.Class.newInstance0(Unknown Source)
      at java.lang.Class.newInstance(Unknown Source)
      at my.own.packacge.MyLauncher.main(MyLauncher.java:##) &lt;- ## pointing to (1)
  Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      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)
      ... 6 more
  </code></pre>
  
  <p>And if I'll uncomment (2) then instance of org.lwjgl.LWJGLException will be successfully created and I can do some things with it! Class org.lwjgl.LWJGLException loaded and works, but game can't use that.
  My question is "HOW? WHY?". </p>
  
  <p>I also decompiled main class of the game, and saw that org.lwjgl.LWJGLException is first import from other JAR:</p>
  
  <pre><code>...
  import some.import.Class;
  import org.lwjgl.LWJGLException;
  import org.lwjgl.Sys;
  import org.lwjgl.input.Keyboard;
  import org.lwjgl.input.Mouse;
  import org.lwjgl.opengl.ContextCapabilities;
  import org.lwjgl.opengl.Display;
  import org.lwjgl.opengl.DisplayMode;
  import org.lwjgl.opengl.GL11;
  import org.lwjgl.opengl.GLContext;
  import org.lwjgl.opengl.PixelFormat;
  import org.lwjgl.util.glu.GLU;
  import other.import.Class;
  ...
  </code></pre>
  
  <p>I'm newbie with ClassLoaders, so maybe i did stupid mistake? I used URLClassLoader because I have not found other simple way to load classes from JAR. I tested it on other project, it works OK. </p>