Importer un jar dynamiquement au runtime

Comment importer un java Jar au runtime:

URLClassLoader child = new URLClassLoader (myJar.toURL(), this.getClass().getClassLoader());
Class classToLoad = Class.forName ("com.MyClassName", true, child);
Method method = classToLoad.getDeclaredMethod ("myMethodName");
Object instance = classToLoad.newInstance ();
Object result = method.invoke (instance);

Laisser un commentaire