Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java verbose class loading

I am trying to list the order in which the Java class loader is loading my classes. if I use -verbose parameter it will list every single interface/class it loads, including tons of interfaces such as Serializable, exceptions etc. Is there a way to tweak this output so it only shows which classes are loaded in the class my main method is defined?

like image 439
Bober02 Avatar asked Apr 19 '12 14:04

Bober02


People also ask

What is verbose in Java?

Verbose is an option that can be used on the Java command to enable debug output for class loading. By default, this debug output is not enabled. This option can be used to determine what location the JDBC driver classes (and any/all other classes) are being loaded from.

How do I enable verbose class loading in Websphere?

In the Server Infrastructure section, open Java and Process Management and select Process Definition. Under Additional Properties, select Java Virtual Machine. Check the Verbose class loading checkbox. Click OK.

How do you load a class in Java?

Load class with forName() method in Java The class object associated with the class with the given string name can be returned with the method java. lang. Class. forName(String name, boolean initialize, ClassLoader loader), using the class loader that is used to load the class.


1 Answers

I guess your best bet is to do the following:

  • Output some fixed text once your main method starts and right before it ends.
  • Pipe the verbose output into a file
  • Use things like less or grep to find the classes loaded between the two tags from the main method.

There's a similar question and some answers here: Is there a way to get which classes a ClassLoader has loaded?

Did you try -verbose:class?

like image 79
nwinkler Avatar answered Sep 20 '22 03:09

nwinkler