I want to implement an application which could use users implemented classes. Each class should be implemented an interface that I define the interfaces and at last, all of classes which implemented by a user, archived in a jar file. Users copy the jar files in to class path and then only give the jar file name to my application. My application should be able to load jar file dynamically. To do this I found this post that is very useful, but it loads classes by class names. I want to load classes based on their parents.
public class A implements iA {
@Override
int getAValue() { ... }
}
public class B implements iB {
@Override
int getBValue() { ... }
}
Suppose loaded jar file has both A
and B
classes. I want to get an instance from class B
by knowing the iB
interface name.
What should I do?