Javassist

Java bytecode manipulation made simple

Project

Project Lead: Shigeru Chiba
Contributing Developers: Bill Burke
Discussion: user forum, development forum
Info: Chiba's Javassist page
Downloads: visit this page
License: You can choose either MPL or LGPL.

Contents

Overview

Javassist (Java programming assistant) is a load-time reflective system for Java. It is a class library for editing bytecodes in Java; it enables Java programs to define a new class at runtime and to modify a class file before the JVM loads it. Unlike other similar systems, Javassist provides source-level abstraction; programmers can modify a class file without detailed knowledge of the Java bytecode. They do not have to even write an inserted bytecode sequence; Javassist instead can compile a fragment of source text on line (for example, just a single statement). This ease of use is a unique feature of Javassit against other tools.

Aspect Oriented Programming: Javassist can be a good tool for introducing new methods into a class and for inserting before/after/around advice at the both caller and callee sides.

Reflection: One of applications of Javassist is runtime reflection; Javassist enables Java programs to use a metaobject that controls method calls on base-level objects. No specialized compiler or virtual machine are needed.

Remote method invocation: Another application is remote method invocation. Javassist enables applets to call a method on a remote object running on the web server. Unlike the Java RMI, the programmer does not need a stub compiler such as rmic; the stub code is dynamically produced by Javassist.

Articles...

Javassist: Java Bytecode Engineering Made Simple
by Shigeru Chiba, Java Developer's Journal, January 2004.

Java programming dynamics, Part 4: Class transformation with Javassist
by Dennis M. Sosnoski, IBM developerWorks, September 16, 2003

Java programming dynamics, Part 5: Transforming classes on-the-fly
by Dennis M. Sosnoski, IBM developerWorks, February 3, 2004.

Java programming dynamics, Part 6: Aspect-oriented changes with Javassist
by Dennis M. Sosnoski, IBM developerWorks, March 2, 2004.

Publications...

An Easy-to-Use Toolkit for Efficient Java Bytecode Translators
Shigeru Chiba and Muga Nishizawa
Proc. of 2nd Int'l Conf. on Generative Programming and Component Engineering (GPCE '03),
LNCS 2830, pp.364-376, Springer-Verlag, 2003.

A Bytecode Translator for Distributed Execution of "Legacy" Java Software
Michiaki Tatsubori, Toshiyuki Sasaki, Shigeru Chiba and Kozo Itano
ECOOP 2001 -- Object-Oriented Programming, LNCS 2072, Springer Verlag, pp.236-255, 2001.

Load-time Structural Reflection in Java
Shigeru Chiba
ECOOP 2000 -- Object-Oriented Programming, LNCS 1850, Springer Verlag, page 313-336, 2000.

Javassist --- A Reflection-based Programming Wizard for Java
Shigeru Chiba
In Proceedings of the ACM OOPSLA'98 Workshop on Reflective Programming in C++ and Java October, 1998.
(An very early sketch of the design of Javassist)

Related Work...

We are developing other reflective systems for C++ and Java.

OpenC++

An extensible C++ preprocessor based on compile-time reflection.

OpenJava

An extensible Java preprocessor based on compile-time reflection.

Acknowledgments...

The development of Javassist is supported in part by Japan Science and Technology Corporation.
[Last Updated: March 12, 2004]

Shigeru Chiba
chiba@acm.org
Copyright (C) 1999-2004 by Shigeru Chiba.
Java(TM) is a trademark of Sun Microsystems, Inc.