0

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.

  • Possible duplicate of [How should I load Jars dynamically at runtime?](http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime) – Andremoniy Jul 28 '16 at 19:43
  • Not quite what I need ... In this way it picks up the jar to load a class with only this child ... I need to load the jar for whole application – Patrick Cavalcanti Jul 28 '16 at 19:51

0 Answers0