Skip navigation links

Package org.plumelib.bcelutil

Utility methods for BCEL, the bytecode engineering library.

See: Description

Package org.plumelib.bcelutil Description

Utility methods for BCEL, the bytecode engineering library.

The Byte Code Engineering Library (Apache Commons BCEL) enables users 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. Such objects can be read from an existing file, be transformed by a program (e.g., a class loader at run time) and written to a file again.

If one wishes to inspect a Java class file, a rough program template would be as follows:

   import org.apache.bcel.classfile.*;

   try {
     // Parse the bytes of the classfile, die on any errors
     ClassParser parser = new ClassParser("path to class file of interest");
     JavaClass jc = parser.parse();
   } catch (Exception e) {
     throw new RuntimeException("Unexpected error", e);
   }
 
At this point one would use the methods of JavaClass, the other members of the org.apache.bcel.classfile package and BcelUtil to explore the class file of interest.

See Also:
InstructionListUtils for notes on modifing a Java class file, Commons BCEL web site for details about the BCEL library
Skip navigation links