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();