Code Examples
Practical code samples referenced throughout the Grails Example tutorial series.
Grails Code Snippets
This page collects code examples that accompany the video tutorials and articles on Grails Example. Each snippet is drawn from the topics covered in the Course Outline, including Groovy fundamentals, application structure, and security configuration.
Creating a WAR File
Package a Grails application for deployment using the grails war command, as covered in the AppFog deployment tutorial.
Groovy Basics
Introductory Groovy syntax examples — variables, closures, and collection operations — from the What is Groovy? article.
Spring Security Setup
Configuration snippets for integrating the Spring Security Core Plugin into a Grails project, referenced in the Basic Security post.
Domain Class Examples
Sample GORM domain classes illustrating constraints, relationships, and custom validation.
Controller Actions
Common controller patterns including CRUD operations, redirects, and parameter binding.
GSP View Helpers
Tag library usage and view templates for rendering dynamic content in Grails Server Pages.
Example: Packaging with grails war
From the AppFog deployment tutorial (posted November 10, 2013), the following command produces a deployable WAR archive:
grails war
Once built, the WAR file is placed in the target/ directory and can be uploaded to a JVM-compatible cloud platform. At the time of writing, AppFog's free tier offered 2 GB of RAM with up to eight provisioned services such as MySQL — sufficient for a basic Grails application consuming roughly 500 MB of RAM.
Example: Basic Security Configuration
The Basic Security article references the Spring Security Core Plugin for Grails. A typical configuration starts with adding the plugin dependency and defining access control rules in application.groovy.
// grails-app/conf/application.groovy
grails.plugin.springsecurity.securityConfigType = "Annotation"
Further patterns for authentication and authorization were explored in an IBM developerWorks article on Grails security, linked from the original post.
Example: Groovy Collection Operations
From the What is Groovy? article, Groovy's concise syntax for working with collections is a cornerstone of Grails development:
def names = ['Alice', 'Bob', 'Charlie']
def uppercased = names.collect { it.toUpperCase() }
// Result: ['ALICE', 'BOB', 'CHARLIE']
Browse by Category
Code examples on the site were organized under categories including Build and Basics, and tagged with labels such as Grails Tutorial. Use the Course Outline to follow the examples in sequence alongside the video lessons.