| 7 | public class TestAddUrl { |
| 8 | |
| 9 | public static void main(String[] args) throws Exception { |
| 10 | URLClassLoader classLoader = (URLClassLoader) TestAddUrl.class.getClassLoader(); |
| 11 | String dir = "./lib"; |
| 12 | Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); |
| 13 | method.setAccessible(true); |
| 14 | method.invoke(classLoader, new File(dir).getAbsoluteFile().toURL()); |
| 15 | |
| 16 | Class klass = Class.forName("HelloKimmking",true, classLoader); |
| 17 | Object obj = klass.newInstance(); |
| 18 | Method hello = klass.getDeclaredMethod("hello"); |
| 19 | hello.invoke(obj); |
| 20 | } |
| 21 | |
| 22 | } |