Grails Guide

Tutorials And Examples on Grails

Groovy Tutorial - Setup Your Windows Environment

When learning a new technology, the first hurdle is to setup your workstation to begin coding. This tutorial will walk through the steps for preparing your Windows box for Groovy development. It will also show you how to create your first "Hello World" Groovy program at the end.

Note

The steps below will assume that Groovy/Grails Tool Suite will be installed. It is an IDE based on Eclipse and ready to run Groovy and Grails application out of the box.

Install Java Development Kit

Groovy/Grails Tool Suite needs Java to be installed to your system. It is recommended to use the latest Java Development Kit (JDK) released from the Oracle website. For this tutorial, JDK 1.7 will be used. The installer is available here (http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html)
gride01
Set the JAVA_HOME environment variable to where you installed the downloaded JDK. It is always a good practice to set this variable on any Java development box.
gride02

Install Groovy/Grails Tool Suite (GGTS)

You can start Groovy development by just using notepad. But I highly recommend the GGTS IDE for convenience in working with Groovy (E.g. syntax highlight). In addition, this IDE is ready if you wish to explore the Grails web framework later.
Go to the website and download your preferred release (http://spring.io/tools/ggts/all)
gride03
And extract the zip to your drive:
gride04
You can then run the IDE application.
Next we need to tell GGTS to use the newly installed JDK 7. Go to Window » Preferences
grxide1
Click Add and then Choose Standard VM. Click Next.
grxide2
Select the folder where JDK 7 was installed and click Finish.
grxide3
Make it the default JRE by selecting it and click then OK.
grxide4

Hello World Goovy Program

If this is your first time with an Eclipse based IDE like GGTS, this is how to create a simple Hello World Groovy Program.
First is to create a new Groovy Project. Go to File » New » Other
grh1
Select Groovy Project and then click Next
grh2
Give it a name and click Finish
grh3
A blank Groovy project will be created. To create a new Groovy class, right click on src and select New » Other.
grh4
Select Groovy Class and then select Next
grh5
Give a name for the class and click Finish.
grh6

Use this code for the class:

package hello
class Hello {
	static main(args) {
		println "Hello World"
	}
}

To run this, right click on the class and select Run As » Groovy Script.
grh7
Ant the output will be displayed at the Console Window.
grh8