I'm trying to make a simple application that loads and runs some classes during runtime. For example, let's say I have this config:
module1.classpath=module1.jar,somelibs1.jar
module1.class=com.blabla.Module1
module2.classpath=module2.jar,somelibs2.jar
module2.class=com.blabla.Module2
Then I need to load libraries specified in module1.classpath
and run the module1.class
with that libraries loaded. Afterwards I need to load module2.classpath
and run module2.clas
s with those libraries.
How do I handle the case when somelibs1.jar
and somelibs2.jar
have the same classes inside? Basically I'd like to run module1.jar
using exclusively somelibs1.jar
and module2.jar
using exclusively somelibs2.jar
. How do I implement that?
I'm guessing I need to create a separate classloader for each of my classes and push the jars in that classloaders. However I'd appreciate some example or at least a confirmation that it is a right way to do that.