如何找到类加载器加载的罐子和顺序? [英] How to find which jars and in what order are loaded by a classloader?

查看:168
本文介绍了如何找到类加载器加载的罐子和顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其他地方找不到这个问题的明确答案,所以我会在这里试试:

I could not find a clear answer to this question elsewhere, so I'll try here:

是否有某种方式(程序化或其他方式)来获取列表应用程序类加载器按照它们加载的精确顺序加载的JAR /类?
By Application Classloader我是指在应用程序服务器(WLS,WAS,JBoss ......)中加载EAR应用程序的类加载器,但很明显,它适用于任何类加载器。

Is there some way (programmatic or other) to get a list of JARs/classes loaded by an Application Classloader in the precise order they were loaded? By Application Classloader I mean the classloader that loads an EAR application in an applications server (WLS, WAS, JBoss...), but obviously, it applies to any classloader.

因此,为了概括,我想知道的是由指定的类加载器加载的JAR的列表和顺序。不是单个类,通过调用classloader.getPackages()很容易找到,但是这个类加载器加载的JAR文件列表。

So, to generalize, what I would like to find out is the list and order of JARs loaded by a specified classloader. Not individual classes, that is easy enough to find out by calling the classloader.getPackages(), but a list of JAR files that were loaded by this classloader.

推荐答案

简短的回答是否定的。类加载器不需要公开它们的搜索逻辑。

The short answer is no. Classloaders are not required to expose their search logic.

但是,如果你的类加载器实例恰好是 URLClassLoader 或子类,然后您可以通过 getURLs()方法。根据此类的文档,将按顺序搜索这些URL。

However, if your classloader instance happens to be URLClassLoader or a subclass, then you do have access to the list of jars/directories, via the getURLs() method. Per the doc for this class, those URLs will be searched in order.

实际上,如果您正在尝试查找从哪里加载类, Steve 的答案可能更有用。

In practice, if you're trying to find out where a class is being loaded from, Steve's answer is probably more useful.

这篇关于如何找到类加载器加载的罐子和顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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