This should help me remember how to run a Groovy script straight from the command line or from within a batch or bash file.

Basically it’s only a matter of

  1. having a copy of groovy-all-x.y.z.jar available
  2. specifying a correct classpath
  3. letting the groovy.ui.GroovyMain class handle business.

The groovy-all-x.y.z.jar is available from the binary groovy distribution. (hint: inside the embeddable folder)

The following one liners assume that the groovy-all-2.4.6.jar is placed inside the lib/ folder, next to the script.


  > java -cp lib/groovy-all-2.4.6.jar;. groovy.ui.Main myscript.groovy
  Hello World!


  > java -cp ./lib/groovy-all-2.4.6.jar:. groovy.ui.GroovyMain myscript.groovy
  Hello World!