Home  >  Article  >  Java  >  How can I get a complete list of all classes loaded in the JVM, including those from specific packages and their descendants?

How can I get a complete list of all classes loaded in the JVM, including those from specific packages and their descendants?

DDD
DDDOriginal
2024-10-25 07:13:02377browse

How can I get a complete list of all classes loaded in the JVM, including those from specific packages and their descendants?

Obtain a Comprehensive List of Classes Loaded in the JVM

Question:

Finding a method to retrieve a complete list of all classes loaded into the JVM, irrespective of their prior load status, is a common requirement. This list should include classes belonging to a specific package and their descendants.

Answer:

While there may not be a direct programmatic solution, there exists a convenient alternative:

Utilizing "-verbose:class" Command-Line Option:

By executing the following command:

java -verbose:class ....

The JVM will provide a verbose readout of all classes being loaded, along with the locations from which they are retrieved. Here's an example of such output:

[Opened /usr/java/j2sdk1.4.1/jre/lib/rt.jar]
[Opened /usr/java/j2sdk1.4.1/jre/lib/sunrsasign.jar]
[Opened /usr/java/j2sdk1.4.1/jre/lib/jsse.jar]
[Opened /usr/java/j2sdk1.4.1/jre/lib/jce.jar]
[Opened /usr/java/j2sdk1.4.1/jre/lib/charsets.jar]
[Loaded java.lang.Object from /usr/java/j2sdk1.4.1/jre/lib/rt.jar]
[Loaded java.io.Serializable from /usr/java/j2sdk1.4.1/jre/lib/rt.jar]
[Loaded java.lang.Comparable from /usr/java/j2sdk1.4.1/jre/lib/rt.jar]
[Loaded java.lang.CharSequence from /usr/java/j2sdk1.4.1/jre/lib/rt.jar]
[Loaded java.lang.String from /usr/java/j2sdk1.4.1/jre/lib/rt.jar]

This output clearly shows the loading process and the source locations of the classes.

For more detailed information, refer to: [JVM -verbose Argument Documentation](https://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#verbose).

The above is the detailed content of How can I get a complete list of all classes loaded in the JVM, including those from specific packages and their descendants?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn