01: /*
02: * Created on Dec 9, 2004
03: *
04: */
05: package org.hammurapi.inspectors.metrics;
06:
07: import java.net.URLClassLoader;
08: import java.util.Iterator;
09: import java.util.Vector;
10:
11: /**
12: * @author 111001082
13: *
14: */
15:
16: public class ListAllLoadedClasses {
17: public static Iterator list(ClassLoader CL)
18: throws NoSuchFieldException, IllegalAccessException {
19: Class CL_class = CL.getClass();
20: while (CL_class != java.lang.ClassLoader.class) {
21: CL_class = CL_class.getSuperclass();
22: }
23: java.lang.reflect.Field ClassLoader_classes_field = CL_class
24: .getDeclaredField("classes");
25: ClassLoader_classes_field.setAccessible(true);
26: Vector classes = (Vector) ClassLoader_classes_field.get(CL);
27: return classes.iterator();
28: }
29:
30: public static void main(String args[]) throws Exception {
31: // URLClassLoader u = new URLClassLoader();
32: System.out.println(System.getProperty("java.class.path", "."));
33:
34: ClassLoader myCL = ListAllLoadedClasses.class.getClassLoader();
35: while (myCL != null) {
36: System.out.println("ClassLoader: " + myCL);
37: for (Iterator iter = list(myCL); iter.hasNext();) {
38: System.out.println("\t" + iter.next());
39: }
40: myCL = myCL.getParent();
41: }
42: }
43: }
|