2

As said, I'd like to change the bytecode during execution. I am not running any sort of application or web server, it's just for a command line program.

Of course I could just create a new ClassLoader, but that's not feasible from the performance point of view.

I ran into JRebel, which should be capable of exactly this things, but I cannot find any examples, tutorial to archive this.

Java Hotswap is not an option, because it cannot deal with multiple Classloaders

Simple example to demonstrate what I want:

Class Car
{
   public void print() { System.out.println("I am Type A"); }
} 

First I wanna load class Car:

Car myCar = new Car();

Do some stuff

myCar.print();  // => I am Type A

Change the source code

sourceCode.replace("Type A", "Type b");

Recompile and change the byte code in the same classloader

Execute same class again

myCar.print(); // => I am Type B

Hope I made my point clear.

Mateusz Chromiński
  • 2,742
  • 4
  • 28
  • 45
Martin
  • 21
  • 1
  • 2

1 Answers1

1

JRebel swaps the bytes for you after you recompile, you do not have to call an API to achieve that.

Anton Arhipov
  • 6,479
  • 1
  • 35
  • 43
  • I do not wanna use jrebel with an application server etc. There wont be any .class files on the filesystem. I just need the functionality to swap byte code in memory – Martin Jul 11 '11 at 10:40
  • that would require some extra code writing indeed. I think SDK could help here http://www.zeroturnaround.com/resources/jrebel-plugins/ – Anton Arhipov Jul 12 '11 at 14:27