Skip to content

Instantly share code, notes, and snippets.

@ansell
Forked from anonymous/CompositeClassLoader.java
Created February 29, 2012 23:40
Show Gist options
  • Save ansell/1945491 to your computer and use it in GitHub Desktop.
Save ansell/1945491 to your computer and use it in GitHub Desktop.
private static class CompositeClassLoader extends ClassLoader {
private Vector<ClassLoader> classLoaders = new Vector<ClassLoader>();
@Override
public URL getResource(String name) {
for (ClassLoader cl : classLoaders) {
URL resource = cl.getResource(name);
if (resource != null)
return resource;
}
return null;
}
@Override
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
for (ClassLoader cl : classLoaders) {
try {
return cl.loadClass(name);
} catch (ClassNotFoundException ex) {
}
}
throw new ClassNotFoundException(name);
}
public void addClassLoader(ClassLoader cl) {
classLoaders.add(cl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment