common-logging 之 classLoader 获取

classLoader 获取分两种形式,一种是JDK1.2之后的,还有种是1.1的,因为在JDK1.2,在Thread类中增加了getContextClassLoader方法。

try{
   //JDK1.2及以后的
   Method method = Thread.class.getMethod("getContextClassLoader", (Class[]) null);
   try {
    classLoader = (ClassLoader)method.invoke(Thread.currentThread(),   (Object[]) null);
   } catch (IllegalAccessException e) { //....}
}catch (NoSuchMethodException e) {
   // Assume we are running on JDK 1.1
   classLoader = getClassLoader(LogFactory.class);
}


你可能感兴趣的:(common-logging 之 classLoader 获取)