0

It may sound stupid but: is it possible to tell Eclipse to change some already compiled code (in a .class file) while debugging?

I would like to check a couple of things for some values. I know that if it is compiled I cannot change it, so it makes no sense to try this. Well, in this concrete case it does make sense.

I am also aware of the hot code replace functionality of Eclipse but it doesn't work for me because it is for source files.

EDIT: In my case I don't want to change the value of a variable. I would like to put a 1 instead of a 0 in this call within a .class file

getTabFolder().setSelection(0);
1
  • If you want to change only values then you can change it in "Variable" view while debugging code. No need for hot code replacement. You can directly change any value at runtime. Commented Aug 8, 2014 at 10:05

3 Answers 3

1

If it is just a variable value you want to change you can do this.

When you are debugging in the debug view of eclipse there is a variables window. If you right click on the variable you wish to change and press 'Change Value' a window will pop up and you can change the value of that variable in there.

Sign up to request clarification or add additional context in comments.

2 Comments

In that case, you cannot achieve what you wish to achieve. You cannot modify a compiled .class class without decompiling and recompiling it.
I know i cannot recompile the class but may be Eclipse provides a tool to handle this situation...
0

I think that you can change body of existing methods, but you cannot add new methods.

You can also change variable values.

Comments

0

It depends, if you are running the code locally Eclipse supports hot swapping.

You can find some info here.

If you change the code While debugging, eclipse will automatically transfer it to the target VM

2 Comments

As I already said, hot swapping doesn't work for me because I want to change a .class
I re-read you question, in that case, you cannot modify a .class as it's already being compiled, you can decompile it and recompile it and restart debugging, but you cannot modify a .class while debugging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.