1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
public static void addURLToSystemClassLoader(URL url) throws IOException {
URLClassLoader systemClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<URLClassLoader> classLoaderClass = URLClassLoader.class;
try {
Method method = classLoaderClass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(systemClassLoader, new Object[] { url });
}
catch (Throwable throwable) {
throwable.printStackTrace();
throw new IOException("addURLToSystemClassLoader() !!!");
}
}
...
addURLToSystemClassLoader(new File("toto.jar").toURI().toURL());
... |
Partager