On Wed, Apr 8, 2009 at 4:30 PM, Alan Bateman <alan.bate...@sun.com> wrote: > Liu lianshun wrote: >> My first question is that, I want to change the java application's >> behavior, in the other words, manipulate the bytecodes of some class when >> running the application without changing the class file itself. Is it >> possible? Can this be done via hacking on the VM, and how? Thanks :)
> An alternative to hacking the VM is to use a java agent (see > java.lang.instrument) or a JVM TI agent. These APIs are designed for > instrumentation purposes but could be used for load-time hacking or > redefining classes at runtime. These APIs are often used in conjunction with > bytecode manipulation libraries like BCEL. Here's a nice, recent blog entry about various alternatives to manipulating bytecode on-the-fly, might give you some ideas http://weblogs.java.net/blog/simonis/archive/2009/02/we_need_a_dirty_1.html Patrick