Replacing a method call in a class at runtime

Problem
I am using fitness to run some automated tests. There is a class called TableTable which, if improved upon, would allow me to do some interesting things. I need to do what the method of appendInstructions()

this class does .

Since fitnesse is explicitly looking for the TableTable class, I can't just create a child TableTable class with my needed enhancements - I can't get find to find and use its own child class.

My current solution The
workaround I made was I borrowed the TableTable source code, added it to my source tree in the same package as the fitness container, and modified its code to suit my needs. My code class files appear before the jar in the pathpath class, so my changes are received.

What I am trying to do
Instead of completely shadowing the TableTable class in the fitness container, I only want to rewrite one method of that class at runtime. Will any code generation library (like cglib) help me rewrite the class at runtime and help me achieve this?

+3


source to share


2 answers


Depending on how extensive your changes are, you can use Javassist to change the body of the method in question . There is a tutorial on intercepting / replacing methods with Javassist here .



+3


source


It looks like you should take a look at JRebel .



+3


source







All Articles