10

I need to read the contents of .class file of java in my java program or is there any method available to read the same.Actually I want to retrieve the local variable table ,line number table,etc from .class file of java but I'm not getting any method to read the same?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Neha
  • 109
  • 1
  • 1
  • 3

3 Answers3

5

I want to retrieve the local variable table ,line number table,etc

To read those you will need ASM, BCEL or a similar bytecode library. Java's reflection API does not tell them to you.

Esko Luontola
  • 73,184
  • 17
  • 117
  • 128
2

You need a Java decompiler or something like that

RoflcoptrException
  • 51,941
  • 35
  • 152
  • 200
  • No ,actually we have to write pure java code.We dont have to use any tool – Neha Apr 01 '11 at 20:12
  • Basically my project is to generate the test cases using white box testing.Normally our NetBeans or eclipse have their own editors,where they can compile their code and also generate the test cases.But waht we have to do is read the .java file stored in the disk anywhere and generate the test cases.And for that we are actually searching for how to get the symbols ,their data type ,its value,etc..And I was thinking to read a .class file as it contains local variable table,line number table,etc. And so we are not using any tool – Neha Apr 01 '11 at 20:36
0

You can get these info using BCEL

The Byte Code Engineering Library is intended to give users a convenient possibility to analyze, create, and manipulate (binary) Java class files (those ending with .class). Classes are represented by objects which contain all the symbolic information of the given class: methods, fields and byte code instructions, in particular.

Or You can also Use Reflection API to get info from class file

jmj
  • 237,923
  • 42
  • 401
  • 438