I always found classloader customization a tricky task. Object2 obj2 = loaderB.loadClass('', true) Object1 obj1 = loaderA.loadClass('', true) Step 8: In System variables, click new and give the values as in. I can figure out a way to load two classes with the same binary name, and it involves to have them loaded (and all their dependencies) by two different classloaders overriding default behaviour.Ī rough example: ClassLoader loaderA = new M圜lassLoader(libPathOne) ĬlassLoader loaderB = new M圜lassLoader(libPathTwo) If you have two classes with the same binary name, searchable by the same classloader, and you want to know which one of them you are loading, you can only inspect the way that specific classloader tries to resolve a class name.Īccording to the java language specification, there is not a uniqueness constraint for a class binary name, but as far as I can see, it should be unique for each classloader. If none of them find a reference to the class you are trying to load you get a ClassNotFoundException. If it does not find a reference to the class you are trying to load, it delegates to its parent, and so on, until you get to the bootstrap class loader. When you instantiate a new class the more specific classloader is invoked. The bootstrap class loader delegates to the appropriate.
You should in any case keep in mind some facts:Ĭlassloaders in an application are usually more than a single one. Classloader related problems are a quite complex matter.