Here you can find the source of addPathToClassPath(String s)
Parameter | Description |
---|---|
s | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
static public void addPathToClassPath(String s) throws Exception
//package com.java2s; // it under the terms of the GNU General Public License as published by // import java.io.File; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; public class Main { /**//ww w . j a v a 2 s . c om * * @param s * @throws Exception */ static public void addPathToClassPath(String s) throws Exception { File f = new File(s); 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 }); } }