1 5 package org.hammurapi.inspectors.metrics; 6 7 import java.net.URLClassLoader ; 8 import java.util.Iterator ; 9 import java.util.Vector ; 10 11 15 16 17 public class ListAllLoadedClasses { 18 public static Iterator list(ClassLoader CL) throws NoSuchFieldException , 19 IllegalAccessException { 20 Class CL_class = CL.getClass(); 21 while (CL_class != java.lang.ClassLoader .class) { 22 CL_class = CL_class.getSuperclass(); 23 } 24 java.lang.reflect.Field ClassLoader_classes_field = CL_class 25 .getDeclaredField("classes"); 26 ClassLoader_classes_field.setAccessible(true); 27 Vector classes = (Vector ) ClassLoader_classes_field.get(CL); 28 return classes.iterator(); 29 } 30 31 public static void main(String args[]) throws Exception { 32 System.out.println( System.getProperty("java.class.path", ".")); 34 35 ClassLoader myCL = ListAllLoadedClasses.class.getClassLoader(); 36 while (myCL != null) { 37 System.out.println("ClassLoader: " + myCL); 38 for (Iterator iter = list(myCL); iter.hasNext();) { 39 System.out.println("\t" + iter.next()); 40 } 41 myCL = myCL.getParent(); 42 } 43 } 44 } 45 46 | Popular Tags |