Is it possible to controll order of loaded classes at runtime? For example: I have class SomeClass which is in two jaras: SomeLibrary-1.0.jar and SomeLibrary-2.0.jar. The class have static method getVersion() which returns current version of SomeLibrary. I use solution found here to modify classpath at runtime. Now, when I run the code:
public static void main(String[] args) {
ClassPathHacker.addFile("SomeLibrary-1.0.jar");
ClassPathHacker.addFile("SomeLibrary-2.0.jar");
System.out.println(SomeClass.getVersion());
}
I expect to see output 2.0
but there is 1.0
instead. This is because class loader use first class found in the class path. Is it possible to control oreder of loaded classes or 'overwrite' class already loaded?