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 is this the best way?
I want to load at run time so that new JARs can be placed in a folder and so load new functionality into my system. As if they were additional modules.