查找从何处加载 java 类 - Find where java class is loaded from

问题:

Does anyone know how to programmaticly find out where the java classloader actually loads the class from?有谁知道如何以编程方式找出 java 类加载器实际从何处加载类?

I often work on large projects where the classpath gets very long and manual searching is not really an option.我经常在类路径很长并且手动搜索不是真正的选择的大型项目中工作。 I recently had a problem where the classloader was loading an incorrect version of a class because it was on the classpath in two different places.我最近遇到了一个问题,类加载器加载了一个不正确的类版本,因为它位于两个不同位置的类路径上。

So how can I get the classloader to tell me where on disk the actual class file is coming from?那么我怎样才能让类加载器告诉我实际的类文件来自磁盘上的哪个位置呢?

Edit: What about if the classloader actually fails to load the class due to a version mismatch (or something else), is there anyway we could find out what file its trying to read before it reads it?编辑:如果类加载器由于版本不匹配(或其他原因)而实际上无法加载类,那么我们是否可以在它读取之前找出它试图读取的文件?


解决方案:

参考一: https://en.stackoom.com/question/xB8
参考二: https://stackoom.com/question/xB8
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章