有没有办法在运行时加载java库(.jar文件),如果它不在类路径上?
解决方法:
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);
资料来源:How should I load Jars dynamically at runtime?