When a Java program reaches a statement you want to inspect, Eclipse on the Linux desktop can pause execution just before that statement runs. A line breakpoint gives the debugger the place to stop.

The application has to reach the statement for the breakpoint to take effect. A line inside a conditional branch is a good place to stop when the input you plan to use takes that branch.

The Debug view shows why a thread stopped and which line it reached. Opening the Debug perspective before launching also avoids the Confirm Perspective Switch prompt that Eclipse can show when a thread suspends in another perspective.

Steps to set a debugger breakpoint in Eclipse:

Start with your runnable local Java project's saved class that contains main open in Eclipse's Java editor. The screenshots show Hello.java from the hello project open in the ~/eclipse-workspace workspace. On a first launch, Eclipse may open a sponsor page in your browser. Step 1 starts once the Java editor is visible.

  1. Click Open Perspective at the right end of the Eclipse toolbar.
  2. Select Debug in the Open Perspective dialog.
  3. Click Open to switch to the Debug perspective.
  4. Double-click the empty marker ruler directly to the left of the executable line where you want Java to pause.

    The example uses line 4 of Hello.java, where System.out.println(greeting); runs. A blue dot beside the line marks the breakpoint.

  5. Click Run on the menu bar.
  6. Point to Debug As in the Run menu to open its submenu.
  7. Click Java Application in the Debug As submenu.
  8. Choose Window > Show View > Debug.
  9. Drag the divider between the Debug view and the editor to the right if the suspension message is clipped.
  10. Confirm that the Debug view reports the thread suspended at a breakpoint in your class on the line you chose.

    For Hello.java, the main thread shows Suspended (breakpoint at line 4 in Hello).

Share this guide