Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1

Groovy Quick Start


[ 24 ]


  1. Add the Groovy bin directory to your PATH. This will be %GROOVY_HOME%\bin
    (Windows) or $GROOVY_HOME/bin on Linux and Unix systems.

  2. Open a new command shell and test your setup by issuing the Groovy
    version command groovy -v.


Windows users can also make use of the Windows Installer, which can
be found at http://www.groovy-lang.org/download.html.

If all goes well, you should see something like the following:


$ groovy -v


Groovy Version: 2.4.4 JVM: 1.8.0_51 Vendor: Oracle Corporation OS: Mac OS
X


Your Groovy installation relies on having a working Java version set up already on
your computer. Groovy will work with any version of Java from 1.4.1 onwards, but
if you want to use some of the language features, such as generics and annotations,
you will need to have a minimum of Java 1.5 installed. You can check your Java
version with the command java -version, if you are not sure. You can find an
upgrade at http://www.oracle.com/technetwork/java/javase/downloads/
index.html.


Running Groovy


Now that you have Groovy installed, let's introduce some of the tools that come with
the Groovy package. Groovy can be compiled into a Java class file and deployed as
part of an application, the same as for any other Java class file. In addition to this,
Groovy has several tools that allow us to execute a Groovy program as a script
without the need to package it into a Java application.


There are three commands that we can use to launch a script. In the following
sections, we will demonstrate the different methods of running Groovy scripts.
As we progress through the book, you can use these methods to execute the
Groovy scripts that we will describe.


http://www.ebook3000.com
Free download pdf