Using the Eclipse Debugger
- Debugging in the Java Development Tooling Environment
- The Debug Perspective
- Debugging Standalone Java Code
- Remote Debugging
- In Brief
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
Brian W. Kernighan
In this chapter
-
Debugging in the Java Development Tooling Environment
-
The Debug Perspective
-
Debugging Standalone Java Code
-
Remote Debugging
Debugging in the Java Development Tooling Environment
No matter how hard you try to make your code bulletproof, at some point you will find yourself confronted with a bug that needs to be examined under the microscope. The Eclipse debug environment gives you the tools you need to examine and exterminate bugs as they surface.
Of course, out of the box, Eclipse only gives you enough debugging capabilities as plain-old Java objects can handle. If you want to debug servlets, you can always use a remote agent (which will be discussed at this end of this chapter), but you are much better off getting a plug-in such as Sysdeo or MyEclipse that gives you native app server support. Also, when you look at the remote agent, it will be in the context of a standalone program, not in terms of connecting to an app server.
On the subject of debugging, much can be said, but the less the better. The methodology of Test-Driven Development is mentioned in various places in this book without going into it in any real depth (you can always read Chapter 6, "High-grade Testing Using JUnit"), but take the opening quote to heart: If you find yourself spending a great deal of time in front of your debugger, perhaps you need to write more, or better, tests. Of course, when you reach the point where all else fails, there is always the all-purpose println().
Debugging in Eclipse happens within the Debug perspective. You can open the Debug perspective in all the usual ways:
From the main menu, select Window, Open Perspective, Debug.
From the main menu, select Window, Open Perspective, Other and then select Debug from the Select Perspective dialog.
From the main menu, select Run, Debug As, and then select the program type to run after opening the Debug perspective.
From the main menu, select Run, Debug to open the Launcher dialog. Once you have created or modified a run configuration, click Debug to run your program after opening the Debug perspective.
From the toolbar, click the bug icon and Eclipse will start the last program you were debugging after opening the Debug perspective.
From the toolbar, click the arrow to the right of the bug icon and select the program to be run after opening the Debug perspective.
As usual, the most important thing to recognize is which of the many ways available to accomplish a task is the most comfortable for you.
Let's look at the Debug perspective and then look at debugging standalone Java code, plug-ins, and server-side Java code as well as remote debugging.