Here you can find the source of addToClassPath(String s)
public static void addToClassPath(String s) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; public class Main { public static void addToClassPath(String s) throws IOException { File f = new File(s); addToClassPath(f);/*w ww . j a v a 2 s. c o m*/ } public static void addToClassPath(File f) throws IOException { addToClassPath(f.toURL()); } public static void addToClassPath(URL u) throws IOException { URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class sysclass = URLClassLoader.class; try { Method method = sysclass.getDeclaredMethod("addURL", new Class[] { URL.class }); method.setAccessible(true); method.invoke(sysloader, new Object[] { u }); } catch (Throwable t) { t.printStackTrace(); throw new IOException("Error, could not add URL to system classloader"); } } }