Skip to content

Instantly share code, notes, and snippets.

@pfmiles
Created April 26, 2016 12:38
Show Gist options
  • Select an option

  • Save pfmiles/4232689225377c7fdedb808313d50352 to your computer and use it in GitHub Desktop.

Select an option

Save pfmiles/4232689225377c7fdedb808313d50352 to your computer and use it in GitHub Desktop.
应用中为自定义classloader获取parent classloader的一般逻辑
private static ClassLoader getParentClsLoader() {
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
if (ctxLoader != null) {
try {
ctxLoader.loadClass(CurrentClass.class.getName());
return ctxLoader;
} catch (ClassNotFoundException e) {
}
}
return CurrentClass.class.getClassLoader();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment