Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Grails Development - Tutorial

Lars Vogel

Version 0.6

07.02.2010

Revision History
Revision 0.115.04.2008Lars Vogel
Started writing this article
Revision 0.215.12.2008Lars Vogel
Started Todo example
Revision 0.306.01.2008Lars Vogel
Error correction
Revision 0.413.06.2009Lars Vogel
Error correction, updated to Grails 1.1.1
Revision 0.516.06.2009Lars Vogel
Improved description
Revision 0.607.02.2010Lars Vogel
Update to Grails 1.2

Grails Webapplication

This article explains how to build a Grails application. This article is based on Java 1.6 and Grails 1.2.x.


Table of Contents

1. Grails
1.1. Overview
1.2. Groovy
2. Installation
3. Create Grails web application
3.1. Create your application
3.2. Run your application
3.3. Stop the server
3.4. Create your domain model
3.5. Dynamic Scaffolding
3.6. Bootstrapping
3.7. Store the data
3.8. Static scaffolding
4. Change the layout of your Grails application
4.1. Changing the generated views
4.2. Using CSS
5. Create a war archive
6. Testing your application
7. Using Eclipse for Grails development
8. Thank you
9. Questions and Discussion
10. Links and Literature
10.1. Grails Links

1. Grails

1.1. Overview

Grails is a web framework based on Groovy and Java which can be deployed into existing Java web servers, e.g. Tomcat or Jetty .

Grails allows to create quickly web applications; its scaffolding capabilities let you create a new project within a new minutes. Grails is based on the the "convention over configuration" idea which allows the application to auto-wires itself based on naming schemes (instead of using configuration files, e.gl XML files).

The Grails framework allows instance development without requiring any configuration. Just download Grails and you are ready to start. Grails accomplish this by automatically providing the Tomcat webcontainer and the HSQLDB database during development. If you deploy you Grails application later you can use another webcontainer or database.

Grails uses GORM (Grails Object Relational Mapping) for the persistence of the domain model. GORM is based on Hibernate. You can test with the HSQLDB and run in production against another database simply by changing the configuration file (DataSource.groovy).

Grails uses JavaEE as the architectural basis and Spring for structuring the application via dependency injection.

Grails is plugin based and provides its own build system (Gant). The Grails homepage provides several pre-defined plugins which extend the Grails framework.

During the start of a new development with Grails you mainly use the command line to generated new user interfaces.

1.2. Groovy

Grails is based on the programming language Groovy .

Groovy is (almost) a superset of Java, e.g. most valid Java constructs are also valid Groovy constructs. Groovy has several advanced features in additonal to the standard Java features, e.g. closures, native support for lists and maps, a shorter syntax and much more. Please see Groovy Tutorial in case you want to get to know Groovy.