I am trying to load classes from a jar file and create instances of those classes. All the classes implement an IModule interface.
The Instance is created succesfully, but whenever I try to cast the object to the IModule type I get ClassCastException.
This is my code:
urlCl = new URLClassLoader(new URL[] { classFile.toURL()},System.class.getClassLoader());
Class projectClass = urlCl.loadClass("Project");
IModule projectObj = (IModule) projectClass.newInstance();
My projects are in eclipse with the IModule being a separate project that is added to the class-path of both the "Project" and the "Loader".
Any suggestions on what I am doing wrong? Thanks.