Is there any contraindication to load libraries (.jar) at runtime?
I found this code that does this:
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(sysloader, new Object[]{URL_LOAD});
} catch (Throwable t) {
t.printStackTrace();
throw new IOException("Error, could not add URL to system classloader");
}
This code works. But it is the best way?
I want to load at run time for new jars can be placed in a folder and thus carry new features to my system. As if they were additional modules.
Aucun commentaire:
Enregistrer un commentaire