Skip to: Site menu | Main content

Groovy 

      Download | Documentation | Developers | Community

An agile dynamic language for the Java Platform

Debugging with JSwat Add comment to Wiki View in Wiki Edit Wiki page Printable Version

Overview 

With Groovy 1.0 JSR-05, it is possible to use JSwat to step-debug with Groovy. JSwat is an open source debugger that uses the Java Platform Debugger Architecture. JSwat is available from the project home page at http://www.bluemarsh.com/java/jswat/. Version 2 is based on Swing and JDK 1.4. Version 2 is also availabe as a jEdit plugin. Version 3 of JSwat requires Java 5 and is build on the Netbeans Platform API. The instruction below pertain to using JSwat v3.9 .

You can use JSwat to debug uncompiled scripts as well compiled Groovy classes. You can step into Groovy methods and classes. You can also pull the Groovy runtime source and step from a script into the underlying Groovy runtime support classes.

Configuring JSwat 

Running Windows XP, all configuration settings are stored in %USERPROFILE%\.jswat. If you want to save the settings somewhere else, you can pass that directory on the command line. For example, if I was to save my settings in c:\myCustomJswatDir,  type jswat --userdir c:\myCustomJswatDir .

Before you get started debugging, you have to configure JSwat classpath and source directory settings. In JSwat, you associate your runtime settings with session name. Groovy jars can be added to your debug session classpath by selecting Session->Settings. In the dialog box that comes up, you change the default session name to something more meaningful, like Groovy Scripting . Then click on the Classes tab and the Add Jars/Folder button to add the Groovy runtime jars. Navigate to your GROOVY_HOME\lib directory and Shift-click all of the jars to add them all at once. Click on the Sources tab and add the directory that contains the scripts you want to debug.

Debugging a Script

To simplest way to get started debugging is to open your script in JSwat, using File->Open File. Single click in the left gutter next the source line you want for a breakpoint. Then click on Sesion->Start . In the Launch Debuggee dialog, enter groovy.lang.GroovyShell for the Class Name:, and the name of your script, i.e. HelloWorld.groovy for Class Arguments:. Click the Launch button and you're now stepping through through your code.

Debugging Compiled Groovy Classes

Compile of your classes with groovyc. Add the directory with the compiled classes to the session classpath by clicking Session->Settings->Classes->Add Jar/Folder. Open your source file in JSwat using using File->Open File and single click in the left gutter next the source line you want for a breakpoint. Then click on Sesion->Start . In the Launch Debuggee dialog, enter the name of the compiled Groovy class, i.e. HelloWorld.class,  that has a main() in it. Click the Launch button and you're now stepping through through your code.

Stepping into the Groovy Runtime

Download the Groovy source archive and unzip it into %GROOVY_HOME%.  Add %GROOVY_HOME%\src\main to the session sources by clicking Session->Settings->Sources->Add Jar/Folder. If click Step Into on a line of source in your script, you will then drop into Groovy runtime and be able to step though that Java code. This is a great way see what is going on under the covers.

Stepping over the Java and Groovy Runtime 

If you're only concerning with stepping into one Groovy script from another and want to by pass all the runtime code, click on Tools->Options->Debugging->General->Stepping Excludes and add the packages you want skip. The following list would probably be a good starting point: groovy., org.codehaus.groovy., gjdk.; java., sun.*,org.apache.*

Debugging Compiled JUnit Tests

Use junit.textui.TestRunner or groovy.lang.GroovyShell for the Class Name and your test class for the Class Arguments.