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

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:
groovy ,debugging ,cli

Published at DZone with permission of Sandra Parsick, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}