aQute.libg.classloaders.URLClassLoaderWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bndlib Show documentation
Show all versions of biz.aQute.bndlib Show documentation
bndlib: A Swiss Army Knife for OSGi
package aQute.libg.classloaders;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
public class URLClassLoaderWrapper {
final URLClassLoader loader;
final Method addURL;
public URLClassLoaderWrapper(ClassLoader loader) throws Exception {
this.loader = (URLClassLoader) loader;
addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURL.setAccessible(true);
}
public void addURL(URL url) throws Exception {
try {
addURL.invoke(loader, url);
} catch (InvocationTargetException ite) {
throw (Exception) ite.getTargetException();
}
}
public Class< ? > loadClass(String name) throws Exception {
return loader.loadClass(name);
}
}