在dubbo中发现一个获取类加载器的好代码
/*** get class loader** @param clazz* @return class loader*/public static ClassLoader getClassLoader(Class<?> clazz) {ClassLoader cl = null;try {cl = Thread.currentThread().getContextClassLoader();} catch (Throwable ex) {// Cannot access thread context ClassLoader - falling back to system class loader...}if (cl == null) {// No thread context class loader -> use class loader of this class.cl = clazz.getClassLoader();if (cl == null) {// getClassLoader() returning null indicates the bootstrap ClassLoadertry {cl = ClassLoader.getSystemClassLoader();} catch (Throwable ex) {// Cannot access system ClassLoader - oh well, maybe the caller can live with null...}}}return cl;}
