Question

Is it possible to get javac flags that was set when a class was compiled? I mean I have a 3rd party library and I can't debug its class in Eclipse because line: not available.

I would like to see what flags was used when the library was compiled. Here is a similar problem I have. Its author writes:

Looking at javac compile flags, I see the -g:none flag.

So is it possible to see those flags?

Was it helpful?

Solution

You can do it with javap util. Run it with -v flag. If src was compiled with -g:source option javap will print file path in the first line of the output

Classfile /D:/workspace/x/target/classes/test/Test2.class
...

if -g:vars was used then you will see var names in LocalVariableTable

  LocalVariableTable:
    Start  Length  Slot  Name   Signature
           0      31     0  args   [Ljava/lang/String;
  ...

if -g:lines was used then javap will print LineNumberTable

LineNumberTable:
 line 12: 0
 ...

You can also read these things programmatically with eg BCEL:

    JavaClass jc = Repository.lookupClass(Test2.class);
    String sf = jc.getSourceFileName();
    Method m = jc.getMethods()[0];
    LineNumberTable ln = m.getLineNumberTable();
    LocalVariableTable lvt = m.getLocalVariableTable();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top