Home  >  Article  >  Java  >  How to List All Classes in a Specific Package, Loaded or Not, in the JVM?

How to List All Classes in a Specific Package, Loaded or Not, in the JVM?

DDD
DDDOriginal
2024-10-26 05:38:02368browse

How to List All Classes in a Specific Package, Loaded or Not, in the JVM?

Get a List of All Classes Loaded in the JVM

Question:

How can I obtain a list of all classes, including their children, belonging to a specific package, regardless of whether they are currently loaded in the JVM?

Answer:

While it's not a programmatic solution, you can employ the java command with the -verbose:class flag:

java -verbose:class ....

The JVM will then log the classes it is loading and their sources:

[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]

For further information, please refer to the following resource: [Verbose Class Loading](https://docs.oracle.com/javase/7/docs/technotes/tools/solaris/java.html#classloading).

The above is the detailed content of How to List All Classes in a Specific Package, Loaded or Not, in the JVM?. 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