Here you can find the source of addJarsToClassPath(String jarPath)
public static void addJarsToClassPath(String jarPath)
//package com.java2s; //License from project: Apache License import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; public class Main { public static void addJarsToClassPath(String jarPath) { if (jarPath != null) { File f = new File(jarPath); try { URL u = f.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[] { u }); } catch (MalformedURLException e) { System.out.println("Invalid jarPath ... " + jarPath); System.out.println(e.getMessage() + ":" + e.getCause()); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { System.out.println("Failed to load jars from : " + jarPath); System.out.println(e.getMessage() + ":" + e.getCause()); }//from www . j av a 2 s . com } } }