I would like to load a class from another JAR (imported as file during runtime) and handover an Object (this) to the Constructor of the class which should be loaded.
I tried doing that with the following code:
URLClassLoader cl2 = URLClassLoader.newInstance(new URL[] { new URL("jar:file:" + jarPath +"!/") });
Class c2 = cl2.loadClass("main.Class2BeLoaded");
Object loadedClass = c2.getConstructor(Object4Constructor.class).newInstance(this));
It seems so, that the Object which I handover to the constructor (this) can't be used from the code which runs in the JAR.
What is wrong? If I run this code in the same JAR everything works.
Aucun commentaire:
Enregistrer un commentaire