Determine whether .class file was compiled with debug info?

后端 未结 3 1983
情话喂你
情话喂你 2020-12-04 15:44

How can I determine for any Java .class file if that was compiled with debug info or not?

How can I tell exactly what -g{source|lines|vars} option was used?

3条回答
  •  攒了一身酷
    2020-12-04 16:17

    Building on the two answers above (Aaron Digulla and Pete Kirkham), you can inspect the jarfile or the classfile directly with javap -v. I find this a little simpler than using a classpath. Single quotes are needed with the ! for the jarfile case.

    javap -v 'jar:file:///Absolute/Path/To/JarFile.jar!/package/name/using/slashes/ClassName.class' | grep "\(Compiled from\|LineNumberTable\|LocalVariableTable\)" | head
    

    or (don't need the absolute path for checking a classfile)

    javap -v Path/To/ClassName.class | grep "\(Compiled from\|LineNumberTable\|LocalVariableTable\)" | head
    

    If results are unclear or the format changes, pipe to less instead of grep and take a look.

提交回复
热议问题