blob: c199a9211194d7c1ab94ea333b39080e63b21db3 [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.libg.classloaders;
2
3import java.lang.reflect.*;
4import java.net.*;
5
6public class URLClassLoaderWrapper {
Stuart McCulloch2286f232012-06-15 13:27:53 +00007 final URLClassLoader loader;
8 final Method addURL;
9
Stuart McCullochbb014372012-06-07 21:57:32 +000010 public URLClassLoaderWrapper(ClassLoader loader) throws Exception {
11 this.loader = (URLClassLoader) loader;
12 addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
13 addURL.setAccessible(true);
14 }
Stuart McCulloch2286f232012-06-15 13:27:53 +000015
16 public void addURL(URL url) throws Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000017 try {
Stuart McCulloch2286f232012-06-15 13:27:53 +000018 addURL.invoke(loader, url);
19 }
20 catch (InvocationTargetException ite) {
Stuart McCullochbb014372012-06-07 21:57:32 +000021 throw (Exception) ite.getTargetException();
22 }
23 }
Stuart McCulloch2286f232012-06-15 13:27:53 +000024
25 public Class< ? > loadClass(String name) throws Exception {
Stuart McCullochbb014372012-06-07 21:57:32 +000026 return loader.loadClass(name);
27 }
28}