找到加载特定类的ClassLoader [英] Find the ClassLoader loading a specific class

查看:108
本文介绍了找到加载特定类的ClassLoader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法确定哪个ClassLoader加载特定的类?或者更具体地说,从特定类的加载位置?

Is there a way to determine which ClassLoader loads a specific class? Or more specifically from where a specific class is loaded?

我遇到了加载旧的db驱动程序类的情况。我想找到加载旧驱动程序的文件。

I've a situation where an old db driver class is loaded. I'd like to find the file where the old driver is loaded from.

我的初始方法是在ClassLoader.loadClass(..)方法上设置调试点一旦类加载后停止vm,看看哪个类加载器正在加载它。不幸的是,loadClass方法经常被调用,很难在类加载的地方停止。我将尝试设置断点过滤器。但是,还有另一个问题:由于ClassLoader体系结构,即使ClassLoader不负责加载,也会调用loadClass。

My initial approach is to set a debug point on the ClassLoader.loadClass(..) method and stop the vm once the class is getting loaded to see which classloader is loading it. Unfortunately the loadClass method is called so often that its difficult to stop where the class is loaded. I'll try to set a breakpoint filter. There is, however, another problem: because of the ClassLoader architecture the loadClass is called even if the ClassLoader is not responsible for loading.

必须有更好的方法来实现我想要的。您是否有想法或建议在哪里寻找解决方案?

There must be a better way to achieve what I want. Do you have an idea or suggestion where to look for a solution?

推荐答案

您如何启动您的计划?

向命令行添加以下选项记录每个正在加载的类的位置。

Adding following option to command line logs location of every class being loaded.

-verbose:class

这些日志通常出现在sysout中。但是根据日志记录的配置方式,您可能需要稍微查看一下。

These logs typically appear in sysout. But depending on how logging is configured you may have to look around a little.

这篇关于找到加载特定类的ClassLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆