How to Write a Basic Groovy Script
Getting started with Groovy can be easy and fun! To create and run a basic script written in Groovy, follow these three steps.
- Open your text editor and create the Groovy script:
The program creates a
// Basic Groovy Script
def name=console.readLine("What is your name? ")
println "Welcome to Groovy, $name!"
Console object in order to read data typed in by the user.
Then the program sends a greeting that contains the name provided by the user.
- Save your file as
- Open a command prompt and navigate to the directory containing your new Groovy program. Then type in the command to interpret and run your script:
When the program prompts you, type your name (I typed "Stephen") and hit Enter. The program will echo back your name with
Author: Stephen Withrow