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!