Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to load library at runtime?

Is there a way to load a java library (.jar file) at runtime, if it is not on the classpath?

like image 279
Rogach Avatar asked Oct 24 '25 00:10

Rogach


1 Answers

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 should I load Jars dynamically at runtime?

like image 73
zengr Avatar answered Oct 26 '25 23:10

zengr