Debugging with Eclipse


Added by Scott Hickey, last edited by Scott Hickey on Dec 12, 2006  (view change)

Labels

 
(None)

It is possible to step through compiled Groovy classes in Eclipse using the Java Debugger by doing the following:

  1. Setup "Step filtering" in Eclipse Window->Preferences->Java->Debug->Step Filtering to enable filtering the default packages and add filtering the following packages: org.codehaus.*, groovy.*
  2. Select Project,Debug and in the popup screen
    1. Select Java Application (not Groovy)
    2.  Select New at the bottom
      • Give an appropriate name (use the Class that you are about to debug)
      • Type the project name that has the class or select using the Browse button
      • Enter the name of the main class

Setup Debugging for JUnit Test Cases

  1. This is the same process as above with the following exceptions:
    • In the Main tab, the main class is always junit.textui.TestRunner
    • In the Arguments tab, the program arguments is where the appropriate class name (use the Class that you are about to debug) is entered. (eg. - mypackge.HelloWorld).

Debugging isn't perfect yet in the plugin but it very usable. Note that you will have to "step into" in closures instead of stepping "over" them; even though they are in the same file, a separate class is created for each closure. Also, when inspecting variables, you may need to drill down through the metaclass to get to the object you are trying to inspect. Adding nicely formatted toString() methods to your Groovy objects greatly facilitates debugging.

The first time you try to debug a closure in Eclipse, you will recieve a dialog box like the one below. Click on the "don't tell me again message" and  continue. You will be able debug  the  closure.