Sunday, October 10, 2010

GonG - Getting Groovy - 1 - Installing Groovy and Grails

This is a quick reference and packaged version of installing, developing and deploying Groovy on Grails (GonG) application.
Trust me, it is much faster, easier and fun that running JSP, JSF, Spring and Hibernate(We will see how to integrate some of these with GonG).
Statutory Warning You could go through the documentation on the Groovy site as well as the grails site instead of proceeding here.

GROOVY

Download Groovy from http://groovy.codehaus.org/Download
At the time of this writing, the latest version is Groovy 1.7.
Download the Groovy 1.7.5 Download zip: Binary Release

Now Unzip it to your installation location. (Windows users, try not to have a space (" ") in the path - if possible. It is fine even if you have one - in case you cant help it.)

Set GROOVY_HOME environment variable to the Groovy installation location.

I use JDK 1.6 - Please the latest one if you do not have this. Anyway the minimum version required for 1.7.5 is JDK 1.5.

Ensure that you have the JAVA_HOME set to your Java installation.

Double click on the groovyConsole.bat in the bin folder.

You get a GroovyConsole GUI. Type in a few Groovy statements like:
And select Run from the console or do Ctrl+R
-------------------------------------------------------------------
println "Yeah Groovy!!"
// Assign a value to a variable
x=1
// INcrement it
x++
// Print it
println x
//Define a Array/ List
y=[10,20,30,40,50]
// Getting one of the elements and printing the count of elements
println y[4]
println y.size()
//Defining a Map - key value pairs
z=["a":10,"b":11,"c":12]
// One way of getting the value using the key "a"
println z.a
// Adding a new map entry
z["d"]=14
// Retrieving Map Entry
println z["b"]
println z["d"]

// Getting a calendar instance, getting the year out of it and printing it
println Calendar.getInstance().get(Calendar.YEAR)
-------------------------------------------------------------------

For a person with a basic knowledge of programming, the comment lines (ones prefixed with //) is an overkill.
And if you are a Java programmer, you should be falling asleep by now.
Now that is the power of groovy. Hear its name, download it, Unzip it, set a few paths and start coding.
Do not underestimate the power of Groovy.
There are advanced features that I will take you through in the coming posts.

So if Groovy is this easy, what happens when it is combined with Grails.
Check out the next section.

GRAILS

Download Grails from http://www.grails.org/Download
Download the Binary Zip - I have downloaded version 1.3.5 (latest when I am writing this).

Unzip the contents to your installation location. (Windows users, try not to have a space (" ") in the path - if possible. It is fine even if you have one - in case you cant help it.)

Set GRAILS_HOME environment variable that points to the path where you extracted
Now append the %GRAILS_HOME>%\bin to the end of your PATH variable.
Make sure that PATH and GRAILS_HOME variable should be in the same environment variable level. (eg. 'System variables') rather than across environment variable levels (eg. PATH under 'System variables' and GRAILS_HOME under 'User variables' - not like this).

Take a command prompt and type in "grails".
You should get a help message, else fix the path issues.

Thats it!! You are all set to start building applications - Groooovy....

The next post discusses on how how to start building the application.

No comments: