Download NetBeans!

20071018 Thursday October 18, 2007

Stepping through Groovy in NetBeans IDE

I put a breakpoint in the Java class I showed yesterday and am now able to step through the Groovy script, with the Local Variables window showing the current state of my Groovy variables:

Funnily enough, Scott Hickey, the main guy behind the Eclipse plugin for Grails and Groovy, is the one who worked with me in (a) coming up with the procedure I outlined yesterday and (b) thinking up the possibility of debugging Groovy, in the way demonstrated above! The Grails eXchange is definitely one of the best conferences I have been to, in terms of people freely exchanging ideas and learning from each other's insights and enthusiasms. The main message I'm going home with is the rather obvious realisation that Groovy is in a completely different category to any other scripting language, because of its relationship with Java. Hence, lots of stuff (such as the Java debugger, as indicated above) can simply be reused when working with Groovy. That insight should also inform the tooling provided for Groovy. The closer we stay to Java, the more we can get from it, the less we'll be reinventing the wheel, and the greater the chance that we'll be providing something truly useful for Groovy users in NetBeans IDE.

Oct 18 2007, 03:26:14 AM PDT Permalink

Trackback URL: http://blogs.sun.com/geertjan/entry/stepping_through_groovy_in_netbeans
Comments:

very cool

Posted by Ramon Ramos on October 18, 2007 at 07:25 AM PDT #

Wow!

Posted by Pan Feng on October 18, 2007 at 07:54 PM PDT #

JSR 223 doesn't support a debug api and since you did mention a groovy compiler in your post yesterday, I'm assuming you have compiled the groovy code to .class files that have debug information mapping back to the original groovy source.

That would let you debug via JDPA certainly but then groovy is not being interpreted so for changes, you'd have to compile and then reload the classes (e.g. hot swap where possible, otherwise restart) vs. an interpreted scripting language (e.g. javascript via 223) where you can literally fix/change the code and keep going as if nothing happened.

Also, are groovy variables typed and/or can their type change dynamically (e.g. x="foo" followed by x=1 being legal, though the type is changing from string to integer?) If so, is the NetBeans debugger displaying this change properly?

Posted by Peter Williams on October 19, 2007 at 02:44 PM PDT #

Peter:

The Groovy interpreter always performs compilation to bytecode on the fly so there is no need for a seperate compile to .class file step for using the debugger.

And variables declared without a type ('def x' or 'x =') are implicitly defined as Object.

Posted by Jim White on October 22, 2007 at 09:14 AM PDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed