Java verbose class loading

后端 未结 2 489
有刺的猬
有刺的猬 2020-11-29 23:02

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 loa

相关标签:
2条回答
  • 2020-11-29 23:38

    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?

    0 讨论(0)
  • 2020-11-29 23:39

    Here's a sed expression that will parse the output of java -verbose:class to produce pairs of loaded class name and its jar file. You can further pipe through a sort to get unique jar files. For example,

    java -verbose:class -version 2>/dev/null |
      sed -ne 's/\[Loaded \(.\+\) from \(.\+\)\]/\2/p' | 
      sort -u
    

    outputs

    /usr/local/jdk1.7.0_67/jre/lib/rt.jar
    
    0 讨论(0)
提交回复
热议问题