Can I load a library at runtime?

Is there a way to load a java library (.jar file) at run time if it is not in the classpath?

+3
source share
1 answer
URLClassLoader child = new URLClassLoader (myJar.toURL(), this.getClass().getClassLoader());
Class classToLoad = Class.forName ("com.MyClass", true, child);
Method method = classToLoad.getDeclaredMethod ("myMethod");
Object instance = classToLoad.newInstance ();
Object result = method.invoke (instance);

Source: How to load Jars dynamically at runtime?

+6
source

Source: https://habr.com/ru/post/1773362/


All Articles