Grails Cookbook - A collection of tutorials and examples

Grails Tutorial for Beginners - Setup Your Windows Development Environment

For most beginners, one of the hardest part in learning a new technology, is to setup their development environment. This tutorial is written to help new Grails programmers to prepare their Windows Development Environment.

Overview

These are the steps for this guide.


Install JDK

Since Grails runs on top of the Java platform, having the Java Development Kit (JDK) in your system is a requirement. For better compatability, I recommend using the JDK version 1.6. As of the time of this writing, JDK 1.7 is already available, but have some minor issues with Grails.
Go to Oracle website and download the JDK installer file. (http://www.oracle.com/technetwork/java/javase/downloads/jdk6u38-downloads-1877406.html)

p100
Just run and follow instructions
p101


Install Grails

Go to Grails website and download the latest version of Grails. (http://grails.org)
p102
And just extract it in your C drive:
p103


Setup Environment Variables

You need to setup your environmet variables. You need to specify the JAVA_HOME, GRAILS_HOME, and the path to their executable programs.
p104
p105
  • JAVA_HOME - is the directory where you installed the JDK. For example: C:\Program Files\Java\jdk1.6.0_38
  • GRAILS_HOME - is the directory where you extracted Grails. For example: C:\grails-2.2.3
  • PATH - Append the executable (bin) directories to the end of the previous value. For example: %PATH%;C:\Program Files\Java\jdk1.6.0_38\bin;C:\grails-2.2.3\bin
You can test if everything is fine by going to command line and issue "javac -version" and "grails -version" command:
p106


Install Groovy/Grails Tool Suite

This step is optional, as you can use just notepad and command line to develop Grails applications. But having an IDE is very convenient. One of the most used free IDE for Grails developmet is Groovy/Grails Tool Suite. Just go to the website and download. (http://www.springsource.org/downloads/sts-ggts)

p107
And extract to your C drive:
p108
Now you can run the program. For example run C:\springsource\ggts-3.3.0.RELEASE\GGTS.exe:
p109
And it should look like this:
p110


Configure Groovy/Grails Tool Suite

We have to make sure that the Java run time of our IDE points to a JDK instead of a JRE. Here are the steps:
Go to Preferences:
p111
Edit Installed JRE if it is pointing to a JRE installation:
p112
Change it to the JDK installation directory installed in the steps above. It is better if you also change the Name:
p113
p114
Make sure you have an installed Grails SDK:
p115


Create and Run a Sample Application

To validate that everything is properly working, we will create a sample project and run it.
From the File Menu, create a new Grails Project:
p116
Give it a name (e.g. sample) and click finish:
p117
The project will be created with default skeleton directories and files.
p118
Open Grails Console:
p119
Type "run-app" and hit the Enter key
p120
Check the console and wait for the message "Server running".
p121
Now you can open the application in your browser to test:
p122
As you can see, by default the skeleton program have a working screen. Complete with styles and some logic. I will add more tutorials on how to use Grails in the future.


Recommended IDE - IntelliJ IDEA

I have been using Grails since 2007 and have implemented multiple projects with it. I initially did not believe that IDE matters with productivity and I just used Open Source IDE. Out of curiosity, I acquired an IntelliJ IDEA license back in December 2012 and never looked back. I now believe that this is head and shoulders above other IDE's for Java and Grails development. Here are some of the features I like:

It understands the structure of a Grails project.


Autocomplete in Groovy code
It has autocomplete feature for domains, services and others.

Even dynamic methods are supported


Objects Passed by Controllers to Views

When objects are passed to views to be used for rendering:

The autocomplete is available for those objects. IntelliJ knows the names of the objects and has autocomplete features for their methods and properties.


CSS
The IDE knows which CSS were included to your layout and provides autocomplete for it:

Custom Tags
If you create a custom tag, the IDE supports autocomplete for it


Version Control Support
Out of the box, IntelliJ supports many of the popular version control system. This is a big time saver because other IDE's takes time to configure VCS and you would usually run into plugin incompatibilities.



These examples are just the tip of the features targetted for the Grails framework. Adding up all the conveniences easily makes me at least 50% more productive. I highly recommend this IDE for all who wants to be serious with Grails programming. To know more about IntelliJ, you may visit their website here.


List of Tutorials for Beginners

Tags: beginner, eclipse, ggts, grails tool suite, ide, jdk, setup, tutorial, windows