For debug reasons, and curiosity, I wish to list all classes loaded to a specific class loader.
Seeing as most methods of a class loader are protected, what is the best way to accomplish what I want?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Instrumentation.getInitiatedClasses(ClassLoader)may do what you want.According to the docs:
I’m not sure what “initiating loader” means though. If that does not give the right result try using the
getAllLoadedClasses()method and manually filtering by ClassLoader.How to get an instance of
InstrumentationOnly the agent JAR (which is separate from the application JAR) can get an instance of the
Instrumentationinterface. A simple way to make it available to the application is to create an agent JAR containing one class with apremainmethod that does nothing but save a reference to theInstrumentationinstance in the system properties.Example agent class:
Example manifest:
The resulting JAR must then be referenced by the application and specified on the command line (with the
-javaagentoption) when launching the application. It might be loaded twice in differentClassLoaders, but that is not a problem since the systemPropertiesis a per-process singleton.Example application class