4
Is there any contraindication in loading 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_CARREGAR});
} catch (Throwable t) {
t.printStackTrace();
throw new IOException("Error, could not add URL to system classloader");
}
This code works. But that’s the best way?
I want to load at runtime so that new Jars can be placed in a folder and load new features to my system. As if they were add-on modules.
Thank you for your reply... And you this certain code this way is much better... today mine is already very similar to this, as it loads from a list of files..
– Patrick Cavalcanti