Wednesday, December 10, 2008

Groovy and Grails setup on Ubuntu

I was looking for a web framework, that easily integrates with most of the opensource platforms, and also provide very strict MVC model for web application development, and came across few options. Options that I evaluated are Rub and Rails ( php), Groovy on Grails ( Java), Django ( Python). And opted to go with Groovy on Grails for its simplicity and support to pring framework.

Here are the steps on how to set it up on Ubuntu :

Install JDK
# sudo aptitude install sun-java6-jdk


Download Groovy and Grails

# wget http://dist.codehaus.org/groovy/distributions/installers/deb/groovy-1.6-beta-1.deb
# wget http://ant-deb-task.googlecode.com/files/grails_1.0.3-1_all.deb


Install Groovy and Grails
# sudo dpkg -i groovy-1.6-beta-1.deb
# sudo dpkg -i grails_1.0.3-1_all.deb


Configure Path
#sudo gedit /etc/environment

Make following changes in environment file
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/share/grails/bin"
JAVA_HOME=/usr/lib/jvm/java-6-sun
#This needs to be the directory where "dpkg" installed your grails
GRAILS_HOME=/usr/share/grails
#This needs to be the directory where "dpkg" installed your groovy
GROOVY_HOME=/usr/share/groovy

SAVE file and "LOGOUT" and "LOGIN" to Ubuntu. This is very important to reload the environment variables.

#grails

This should return following data :

Welcome to Grails 1.0.3 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails

No script name specified. Use 'grails help' for more info or 'grails interactive' to enter interactive mode


NOTE: If in the above message, the version number of Grails is not shown, then there is something wrong with the installation. I experienced this problem with version 1.0.4 beta, where the version was showing as "null", and hence I was not able to install plugins at a later time. With Groovy 1.6 beta and Grails 1.0.3 it all worked fine. Follow this link to learn more about this issue : http://markmail.org/message/a3qhdoi6rcwiqua6.

Building a sample login app with Grails :

# grails create-app samplelogin
# cd samplelogin
# grails install-plugin acegi
# grails create-auth-domains User Role Requestmap
# grails generate-manager
# grails generate-registration
# grails create-controller Secure
# grails run-app


That's it. Now you can connect to your Grails app by going to
http://localhost:8080/samplelogin

The default UI source files are located at this directory structure:
samplelogin/web-apps

Note : Files in Grails will have an extension as .gsp

FAQ :

1. Where can I find some sample apps on Grails ?
http://www.grails.org/Tutorials

2. How to I change default port settings for grails application ?
You can change the port number at command line
# grails -Dserver.port=9090 run-app
Or you can also configure the port in this config file :
GRAILS_HOME/scripts/Init.groovy

3. Where can I find command line reference for Grails commands ?
http://docs.codehaus.org/display/GRAILS/Command+Line

Reference links:

Grails and Groovy Installation steps
Grails main Home.
Groovy Main Home.
Grails Tutorials.