0

I want to get all the class names loaded in JVM for my tomcat service. Is there any way to get it using java... I have seen Reflection, but it's for a specific class loader and it's not giving classes loaded in JVM.

Iam8139
  • 71
  • 6

2 Answers2

1

The canonical way to get all loaded classes from Java is to call Instrumentation.getAllLoadedClasses() from the Instrumentation API.

However, this requires an instance of Instrumentation, which is available only to Java Agents. If you can't (or don't want to) start your application with an agent, it's possible to attach ByteBuddyAgent in runtime:

Instrumentation inst = ByteBuddyAgent.install();
Class[] loadedClasses = inst.getAllLoadedClasses();
apangin
  • 92,924
  • 10
  • 193
  • 247
  • Thanks for the answer. I haven't checked it, but I can solve the problem by following on to this answer: https://stackoverflow.com/a/2065626/15610843 – Iam8139 Apr 22 '21 at 07:04
-1

You can see Enable Logging with the JVM Unified Logging Framework and do like this

java -Xlog:class+load=info:classloaded.txt
kameshsr
  • 327
  • 3
  • 13