2011-12-11 8 views
1

「shared/lib」 Geronimo Serverのディレクトリにあるjarファイルへのアクセス方法を教えてください。
次のコードを使用してクラスローダー階層を歩いていますが、 "shared/lib '"フォルダーにあるjarsライブラリーを取得できません。どのように私はこれを行うことができます任意のアイデア?次のコードは、サーバーの起動時にサーブレットのコンテキストリスナーで実行されます。ここでTomcatコンテナを使用したGeronimoでのカスタム注釈スキャン

ClassLoader c = Thread.currentThread().getContextClassLoader(); 
    while(c!=null) { 
     System.out.println("CLASS Loader TYPE : " + c.getClass().getName()); 

     if(URLClassLoader.class.isInstance(c)){ 

      URLClassLoader urlclazz = (URLClassLoader) c; 
      for(URL u : urlclazz.getURLs()) { 
       System.out.println("SCANNING : " + u); 

      } 
     }else{ 
      System.out.println("CLASS Loader : " + c.getClass().getName()); 

     } 
     c = c.getParent(); 
    } 

プットを出しサンプルです:

INFO | jvm 1 | 2001/12/10 19:03:30 | CLASS Loader TYPE : org.apache.geronimo.kernel.classloader.JarFileClassLoader 
INFO | jvm 1 | 2011/12/10 19:03:30 | SCANNING : file:/C:/v3app/CORE/webapps/cmsample/WEB-INF/classes/ 
INFO | jvm 1 | 2011/12/10 19:07:32 | CLASS Loader TYPE : sun.misc.Launcher$AppClassLoader 
INFO | jvm 1 | 2011/12/10 19:07:32 | SCANNING : file:/C:/v3app/CORE/lib/wrapper.jar 
INFO | jvm 1 | 2011/12/10 19:07:32 | SCANNING : file:/C:/v3app/CORE/bin/server.jar 
INFO | jvm 1 | 2011/12/10 19:07:32 | SCANNING : file:/C:/v3app/CORE/bin/shutdown.jar 
INFO | jvm 1 | 2011/12/10 19:07:39 | CLASS Loader TYPE : sun.misc.Launcher$ExtClassLoader     == Boot strap Class Loader() 
INFO | jvm 1 | 2011/12/10 19:07:41 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/activation.jar 
INFO | jvm 1 | 2011/12/10 19:07:42 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/CmpCrmf.jar 
INFO | jvm 1 | 2011/12/10 19:07:43 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/dnsns.jar 
INFO | jvm 1 | 2011/12/10 19:07:43 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/dtfj-interface.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/dtfj.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/dtfjview.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/gskikm.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/healthcenter.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/ibmcmsprovider.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/ibmjcefips.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/ibmjceprovider.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/ibmkeycert.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/IBMKeyManagementServer.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/ibmpkcs11impl.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/ibmsaslprovider.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/ibmxmlencprovider.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/jaccess.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/JawBridge.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/jdmpview.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/localedata.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/mail.jar 
INFO | jvm 1 | 2011/12/10 19:07:44 | SCANNING : file:/C:/v3java/CORE/jre/lib/ext/xmlencfw.jar 

答えて

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()); 
      } 
     } 
関連する問題