将Jar添加到Classpath
/** n o w j a v a . c o m - 时代Java 提 供 **/ //package com.nowjava; import java.io.File; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; public class Main { public static void addJarToClasspath(File jarFile) { try { URL url = jarFile.toURI().toURL(); URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader/**from nowjava**/ .getSystemClassLoader(); Class<?> urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", new Class<?>[] { URL.class }); method.setAccessible(true);