How to Obtain a List of Classes Loaded in the JVM
One may desire a comprehensive listing of all classes currently within the Java Virtual Machine (JVM), encompassing both those already loaded and potentially unloaded ones. While programmatic solutions for this task do exist, this article presents an alternative approach.
Utilizing Java's -verbose:class Option
The JVM provides a built-in option that transparently reveals the loading and unloading of classes. By invoking Java with the -verbose:class flag, you can witness a detailed log of these events:
java -verbose:class ....
The output will resemble the following:
[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]
Benefits of the -verbose:class Approach
This method has several advantages:
The above is the detailed content of How to List All Classes Loaded in the JVM: A Simple Approach Using the -verbose:class Option?. For more information, please follow other related articles on the PHP Chinese website!