Here you can find the source of addJarToClasspath(File jarFile)
public static void addJarToClasspath(File jarFile)
//package com.java2s; //License from project: Open Source License 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 {/*from w w w .jav a 2 s. c o m*/ URL url = jarFile.toURI().toURL(); URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader .getSystemClassLoader(); Class<?> urlClass = URLClassLoader.class; Method method = urlClass.getDeclaredMethod("addURL", new Class<?>[] { URL.class }); method.setAccessible(true); method.invoke(urlClassLoader, new Object[] { url }); } catch (Throwable t) { t.printStackTrace(); } } }