public static void addToClasspath ( final URL url , final ClassLoader classLoader ) { checkNotNull ( "url" , url ) ; checkNotNull ( "classLoader" , classLoader ) ; if ( ! ( classLoader instanceof URLClassLoader ) ) { throw new IllegalArgumentException ( "Cannot add '" + url + "' to classloader because it's not an URL classloader" ) ; } final URLClassLoader urlClassLoader = ( URLClassLoader ) classLoader ; if ( ! containsURL ( urlClassLoader . getURLs ( ) , url ) ) { try { final Method addURL = URLClassLoader . class . getDeclaredMethod ( "addURL" , new Class [ ] { URL . class } ) ; addURL . setAccessible ( true ) ; addURL . invoke ( urlClassLoader , new Object [ ] { url } ) ; } catch ( final NoSuchMethodException e ) { throw new RuntimeException ( e ) ; } catch ( final IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( final IllegalAccessException e ) { throw new RuntimeException ( e ) ; } catch ( final InvocationTargetException e ) { throw new RuntimeException ( e ) ; } } }
Adds an URL to the class path .