How to find which jars and in what order are loaded by a classloader?

后端 未结 4 1143
离开以前
离开以前 2020-12-12 20:37

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

Is there some way (programmatic or other) to get a list of JARs/classes loaded by an A

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 21:18

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

    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.

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

提交回复
热议问题