如何探索从哪些JAR加载哪些类? [英] How to explore which classes are loaded from which JARs?

查看:84
本文介绍了如何探索从哪些JAR加载哪些类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法确定哪些类在运行时从哪些jar加载?

Is there a way to determine which classes are loaded from which jars at runtime?

我确信我们之前都已经在JAR地狱了。我在项目上遇到了很多故障排除 ClassNotFoundException s和 NoClassDefFoundError s。我想避免在罐子里找到一个类的所有实例,并在代码上使用消除过程导致CNFE找到罪魁祸首。

I'm sure we've all been in JAR hell before. I've run across this problem a lot troubleshooting ClassNotFoundExceptions and NoClassDefFoundErrors on projects. I'd like to avoid finding all instances of a class in jars and using process of elimination on the code causing a CNFE to find the culprit.

是否会进行任何分析或管理工具给你这种信息?

Will any profiling or management tools give you this kind of information?

这个问题非常烦人,因为我们应该在课程加载时获得这些信息。必须有一种方法可以达到它,或记录并找到它,但我知道什么都不会做到这一点,对吗?

This problem is super annoying purely because we should have this information at the time the class gets loaded. There has to be a way to get to it, or record it and find it, yet I know of nothing that will do this, do you?

我知道OSGi和版本化的捆绑/模块旨在使这个问题成为一个问题...但它似乎不会很快消失。 :)

I know OSGi and versioned bundles/modules aim to make this a non issue... but it doesnt seem to be going away any time soon. :)

注意:我发现这是问题是我的问题的一个子集,与从版本化的jar加载的类有关。

NOTE: I found this question is a subset of my question related to classes loaded from versioned jars.

更新:有点相关,这篇文章解释了在jars(在当前目录下)或M2_REPO中搜索类的策略。 JarScan,扫描所有子文件夹中的所有JAR文件特定课程

Update: Somewhat related, this post explains a strategy to search for a class within jars (either under the current directory) or in your M2_REPO. JarScan, scan all JAR files in all subfolders for specific class

更新2 :也有些相关, JBoss Tattletale

推荐答案

传递 -verbose:class 切换到 java 命令将打印加载的每个类及其加载位置。

Passing the -verbose:class switch to the java command will print each class loaded and where it was loaded from.

Joops 也是查找失踪的好工具提前上课。

Joops is also a nice tool for finding missing classes ahead of time.

这篇关于如何探索从哪些JAR加载哪些类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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