使用 Tomcat 容器在 Geronimo 下扫描自定义注释

发布于 2024-12-20 09:19:25 字数 3736 浏览 2 评论 0原文

我们如何访问 Geronimo Server 的 “shared/lib” 目录中的 jar?
我正在使用以下代码来遍历类加载器层次结构,但无法获取在“shared/lib”文件夹中找到的 jar 库。知道我该怎么做吗?服务器启动时,以下代码在 Servlet 上下文侦听器中执行 非常感谢任何帮助?

    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

How do we get access to the jars that are in “shared/lib” directory of Geronimo Server ?
I am using following code to walk through the class loader hierarchy, but unable to get jars libraries found in “shared/lib’” folder. Any idea how I can do this? Following code is executed in Servlet context listener when server start-up Any help is greatly appreciated ?

    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();
    }

Here is sample out put:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2024-12-27 09:19:25

以下代码正在运行:

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());
            }
        }

Following code is working:

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());
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文