61

In most programming languages I've used, when debugging, when I hit a breakpoint, I have the ability to execute arbitrary code (whatever I type into the console after the breakpoint has been hit).

How do I do this in Eclipse? The debugging mode has, by default, a display console, but no interactive console (into which I can input Java code for immediate execution)

Aaron Fi
  • 10,116
  • 13
  • 66
  • 91

2 Answers2

90

You can use the Display view to execute arbitrary code, access it via:

window->Show View->Display

then type the code you want to execute (you can use CTRL+SPACE for autocomplete).

to execute the code, select it then:

CTRL+SHIFT+D

That should execute the code based on the breakpoint you've hit.

alt text

Note: As of 2018, Display View has been renamed to Debug Shell View.

Nuri
  • 114
  • 6
Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150
  • 7
    ah... that's a little clunky. isn't there an interactive-top-level in which I can simply type, and then hit enter and have my code executed? and have an input history of my entries maintained (similar to up/down arrow on any linux command line)? – Aaron Fi May 16 '09 at 01:20
  • 1
    It is top level, as long you set it in your debug perspective it'll be there always. You can type an expression into that. I have no idea why you need to select it to execute it. I agree it's a bit clunky... it does what you're asking though :) no history.. ooh err... but you can convert to a watch expression after you've done it so I guess that suffices. – Jonathan Holloway May 16 '09 at 01:28
  • 1
    Ctrl+Shift+D does NOT work for me. I am in a Mac so also tried Cmd + Shift + D but non luck. – nacho4d Aug 26 '15 at 14:20
  • 1
    In Mac , one needs to select the line in Display windows and do Command + Shift + D. It worked perfectly for me @nacho4d – vikramvi Jun 15 '16 at 10:43
2

Eclipse has it indeed. Window->Show View->Interactive Console. Note that you can also execute expressions in the Watch view (e.g. result=false, exception.printStackTrace() etc.).

digitalbreed
  • 3,953
  • 4
  • 26
  • 24
  • 6
    My eclipse doesn't have an entry for Interactive Console. Just console. I'll keep poking around - at least I know the feature exists. Thanks. – Aaron Fi May 16 '09 at 01:13
  • 1
    I suspect digitalbreed meant just Console. My Fedora Eclipse 3.4.1 installation has no Interactive Console. You can type input there if your program is waiting for input for something to continue. It doesn't execute artibrary code though. – Jay R. May 16 '09 at 14:29
  • 1
    No, I wasn't referring to the Console. But I suspect the Interactive Console I have comes with the Google Plugin... sorry for the confusion. – digitalbreed May 16 '09 at 18:21
  • @digitalbreed Hi, so I installed Google plugin for Eclipse Neon 4.6.1 and it still doesn't have a interactive console... Can you help me out? I really want one. Thx! – Tony Chen Dec 24 '16 at 05:36
  • @TonyChen the thread is more than seven years old and I switched to IntelliJ years ago, so unfortunately I can't help anymore. – digitalbreed Dec 27 '16 at 11:23