Saturday, July 19, 2008

My favorite Eclipse view

Have you discovered the Display view in the Eclipse debugger? It is my personal favorite. In it, you can execute any Java code in the context of a running debugger.

To open this view, select Window > Show View > Display.

When the debugger hits a break point, you can type some Java code in the Display view. The Java code can use the local variables in the currently selected frame in the Debug view.



To execute the code and display the returned value, push the button with a "J":



If you just want to execute some code that doesn't return a value, push the button with an arrow ">" and a "J":



The standard output will be printed to the Console view:



This is incredibly useful! You can for instance run some code in a debugger and run some complex debugging code, or prototype some code for a new method.

11 comments:

Richard said...

Yea, I found this about a year ago. Can't believe that such a useful feature is not really publicized.

Keith Sader said...

It's not often someone turns me onto a really useful new eclipse feature. Thanks for blogging this and for having someone Dzone it!

Baskaran Rajendran said...

Thanks! was very useful

Anonymous said...

Does anyone know the keyboard shortcuts for those two buttons?
Looks like a very useful view!

Arun said...

A very good one. Thanks for sharing and special thanks for the crystal-clear screenshots.

Anonymous said...

I found out the shortcut, its ctrl + shift + D

Anonymous said...

Excellent find.I was not aware of this until now although I used debug view for some time now !

murugan said...

Excellent one and also very useful.

Murugan said...

Good one and very useful also.

James E. Ervin, IV said...

You know if Eclipse would let you write in a dynamic language like Groovy.... it could be far cooler :) I think it would be appropriate since you are not writing production code there and Groovy's terseness would well IMHO kick butt...

Anonymous said...

Eclipse really should make this capability more obvious...they should probably give it a better name like "code injection" or "execute code." I wrote a whole little tool to compile and run code in a project I was doing, and then another developer showed me this...