Grails Hello World Application

Do you like this?

Summary:
This includes a quick note on how to set up the environment and gives you a feeling of how applications are developed by Grails.


Content:

I got into a few problems when running the latest version of grails such as Grails Unsupported major.minor version 51.0 Problem. Even though I know the issue came from the fact I was running a JDK version higher than the supported one, I couldn't fix the problems. After hours of trying, I found matching versions for all the installations as below.

  • Groovy 2.3.7
  • Grails 2.2.3
  • Java 1.6.0_32
Apart from Java JDK which you have to set up by yourself before continuing, we will be using GVM, the Groovy enVironment Manager, to set up the environment.
curl -s get.gvmtool.net | bash
source "~/.gvm/bin/gvm-init.sh"
gvm install groovy 2.3.7
gvm install grails 2.2.3
grails -version
grails create-app hello
cd hello/
grails create-domain-class test.User
grails shell
Edit the file hello\grails-app\domain\test\User.groovy as following.
package test

class User {

    static constraints = {
    	name(nullable: false)
    }
    String name
}
When grails shell is activated, you can run the following commands to test out your application.
import test.User
u= new User()
u.save() //this user will not be saved because name property is required
u.name="test"
u.save() //this time, it will be saved because it passes the validation

 
comments powered by Disqus