ClassLoader
s have a parent to which load requests are delegated first. To ensure that the new class loader you are creating can access the class Expansion
you should set the parent of the new ClassLoader
to the ClassLoader
of your class Expansion
:
ClassLoader myLoader=new
URLClassLoader
(urls, Expansion.class.getClassLoader());
This does not only ensure that the Expansion
class will be found by myLoader
, it will also guaranty that it resolves to the same runtime class (as the parent is asked first). This is important if the plugin jar contains a copy of the class.