简体   繁体   中英

How to get a list of all classes that are loaded by the bootstrap class loader?

I'm trying to figure out how to unload classes.

Unloading classes in java?

However, I wish to be able to figure out what classes are already loaded. How can this be found?

Only as an alternative to Andres answer you can turn on -verbose:class and redirect stdout to a file. There we'll get this log

...
[Loaded java.lang.Object from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.io.Serializable from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.Comparable from C:\Program Files\Java\jre7\lib\rt.jar]
...

We can extract a class name, load it

Class cls = Class.forName(className); 

if cls.getClassLoader() returns null it was loaded with bootstrap class loader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM