1
4

1 に答える 1

1

次のコードが機能しています:

ClassLoader c =  Thread.currentThread().getContextClassLoader();
Class<? extends ClassLoader > geronimoClazz =  null;
Method parentesMethod = null;

try{
            geronimoClazz = (Class<? extends ClassLoader>) Class.forName("org.apache.geronimo.kernel.config.MultiParentClassLoader");
            parentesMethod = geronimoClazz.getMethod("getParents", null);
        }catch(ClassNotFoundException e){
            // OK KEEP ME not Geronimo Container....it is ok..
        }catch(NoSuchMethodException ne){
            // OK KEEP ME HERE...
        }           
        java.util.Queue<ClassLoader> queue = new LinkedList<ClassLoader>();
        queue.add(c);

        while (!queue.isEmpty()) {
            c = queue.poll();
            if (URLClassLoader.class.isInstance(c)) {
                    URLClassLoader urlclazz = (URLClassLoader) c;
                for (URL u : urlclazz.getURLs()) {
                    System.out.println("SCANNING : " + u);

                }

                if (geronimoClazz != null && 
                        geronimoClazz.isInstance(c) ){

                    try {
                        ClassLoader[]  loaders =  (ClassLoader[])parentesMethod.invoke(c,null);
                        if(loaders != null){
                            for(ClassLoader ld :loaders){
                                // add each one of the class loader to queue..
                                queue.offer(ld);
                            }
                        }

                    } catch (Exception e) {

                    }
                }

            } else {
                System.out.println("CLASS Loader Type : " + c.getClass().getName());
            }
            if(c.getParent() != null){
                queue.offer(c.getParent());
            }
        }
于 2011-12-13T20:34:32.900 に答える