I need to add a jar at run time from path provided in the config file. Let us call it run-time.jar
.
My original jar is original.jar
. I am importing classes from run-time.jar
directly in my original.jar
. At compilation time I have a sample version of run-time.jar
to help me through compilation issues. I am building a thin jar with out dependencies.
I am planning to use URLClassLoader
to load classes at run time. My sample code in original.jar
is
// Importing class from run-time.jar
import run.time.Test
class Original {
public static void main(String[] args) {
/*Code to load classes from jar file*/
Test newTest = new Test();
newTest.runTests();
}
}
Will this approach work or is there any suggestion to do it better. Any help is appreciated. Thanks!!