Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Debug a Groovy Script From Shell

DZone's Guide to

How to Debug a Groovy Script From Shell

Groovy is a dynamic language with powerful capabilities for typing and compilation on the Java platform; use this snippet to debug it without compiling.

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Groovy is a scripting language, so it is possible to run Groovy code without compiling to Java byte code. The necessary condition is that Groovy is installed on your machine. Then, running a Groovy script in a shell looks like the following line:

~>groovy TestScript.groovy

Now, something is wrong with the script on a special environment. You want to debug your Groovy script from the shell.

Fortunately, it works for Groovy just like for Java. You only have to export the Java options for debugging:

~>export JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y"

Now, we can debug our script running from the shell with our favorite IDE.

~>groovy TestScript.groovy
Listening for transport dt_socket at address: 4000

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:
groovy ,debugging ,cli

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}