title: NoClassDefFoundError (change class name)
body: <p>I tried to change a classname by overriding the loadClass(String, Boolean) method.</p>
  
  <p>I am creating a BukkitPlugin. The Bukkitsource can be found <a href="http://jd.bukkit.org/rb/doxygen/" rel="nofollow">here</a></p>
  
  <p>The classloader itself is working fine, i tested it and all the classes worked fine, the error started to occur after i started to change the classnames.</p>
  
  <p>Here is the Method:</p>
  
  <pre><code>import java.io.File;
  import java.lang.reflect.Field;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.HashMap;
  
  import org.bukkit.plugin.java.JavaPlugin;
  
  public class PluginClassLoader extends URLClassLoader {
  
      private final HashMap&lt;String, String&gt; replace;
  
      public PluginClassLoader(JavaPlugin p, HashMap&lt;String, String&gt; replace) throws Exception {
          super(new URL[0], p.getClass().getClassLoader());
          this.replace = replace;
          File f = null;
          Field file = JavaPlugin.class.getDeclaredField("file");
          file.setAccessible(true);
          f = (File) file.get(p);
          addURL(f.toURI().toURL());
      }
  
      private final HashMap&lt;String, Class&lt;?&gt;&gt; classes = new HashMap&lt;&gt;();
  
      @Override
      public Class&lt;?&gt; loadClass(String name) throws ClassNotFoundException {
          String s = replace.get(name);
          if(s != null)
              name = s;
          Class&lt;?&gt; c;
          try {
              c = findClass(name);
          } catch (Exception e) {
              c = super.loadClass(name);
          }
          return c;
      }
  
  
  
  
      @Override
      protected Class&lt;?&gt; loadClass(String name, boolean b)
          throws ClassNotFoundException {
          String s = replace.get(name);
          if(s != null)
              name = s;
          Class&lt;?&gt; c;
          try {
              c = findClass(name);
          } catch (ClassNotFoundException e) {
              c = super.loadClass(name, b);
          }
          return c;
      }
  
      @Override
      protected Class&lt;?&gt; findClass(String name) throws ClassNotFoundException {
          if ((name.startsWith("org.bukkit."))
                  || (name.startsWith("net.minecraft."))) {
              throw new ClassNotFoundException(name);
          }
  
          Class&lt;?&gt; result = classes.get(name);
  
          if (result == null) {
              result = super.findClass(name);
              classes.put(name, result);
          }
          return result;
  
      }
  }
  </code></pre>
  
  <p>And when i use the classloader i get a NoClassDefFoundError everytime i use one of the replaced classes. My best guess is that i have to override another method, but I dont know what it could be.</p>
  
  <p>The ErrorLog:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: org/bukkit/craftbukkit/v1_5_R3/CraftServer
  at me.leo.itemeffects.IEPlugin.onEnable(IEPlugin.java:25)
  at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
  at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
  at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
  at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugin(CraftServer.java:282)
  at org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.java:264)
  at net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:313)
  at net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:290)
  at net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:250)
  at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:151)
  at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:391)
  at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
  </code></pre>
  
  <p>IEPlugin.java:25 is this:</p>
  
  <pre><code>CraftServer server = (CraftServer) Bukkit.getServer();
  </code></pre>
  
  <p>The jvm is searching for the wrong classDefinition, it looks for the one with package 'v1_5_R3', but I replaced the name of the class in loadClass() with 'v1_6_R2'</p>
  
  <p>I am replacing the classname 'org.bukkit.craftbukkit.v1_5_R3.CraftServer with 'org.bukkit.craftbukkit.v1_6_R2.CraftServer'</p>
  
  <p>The class in the package with v1_5_R3 does not exist, that why i change it to v1_6_R2 in the loadClass(String, Boolean) Method</p>
  
  <p>Thanks for reading and for your hopefully forthcoming solutions.</p>