2. Index
1. Introduction and Advantage
2. Features
3. Installation
4. Convention over Configuration
5. Running Application
6. Testing and Application
7. Deploying an Application
8. Generating an Application
9. Configuration
3. Introduction and Advantage
Grails is a full stack framework.
● An easy to use ORM layer built on Hibernate
● An expressive view technology called Groovy Server Page
● A controller layer built on Spring MVC
● An embedded tomcat container which is configured for on the fly
reloading
● Dependency Injection with the inbuilt Spring Container
● Support internationalization
● A transactional service layer built on Spring’s transaction abstraction.
4. Features
1. Easy to set-up and get started
2. DRY (Don’t repeat yourself)
3. Convention and Configuration
4. No painful XML
5. Scaffolding
6. Built-in REST api
7. Tag lib
8. Plugin based development
9. Tons of available plugins
10.Minimal server restart required while development
5. Installation
Before installing grails, make sure that Java SDK 1.4 or higher is installed on your machine.
Set JAVA_HOME environmental variable to point to the path where you have installed Java
1. Download the grails latest version from http://www.grails.org/Download
2. Extract it on the appropriate location…say C:grails
3. Create an environmental variable GRAILS_HOME which points to the path of installation of grails…i.e C:grails
4. In the PATH environment variable.. point it to the /bin directory of grails i.e %GRAILS_HOME%bin
In a nutshell, the environmental variables should be like..
JAVA_HOME = C:Program FilesJavajdk-1.5
GRAILS_HOME = C:grails
PATH = %GRAILS_HOME%bin;%JAVA_HOME%bin;
Check version of grails via grails --version
6. Convention over Configuration
Grails uses “convention over configuration” to configure itself.
This typically means that the name and location of files is used instead of
explicit configuration.
1. Conf :- Configuration Sources
2. Controllers :- Web Controllers
3. Domain :- Application Model
4. Views :- Server Pages
5. Taglib :- Tag Libraries
6. Src :- Supporting Sources
7. Test :- Unit and Integration Testing
7.
8. ● Creating an Application
○ grails create-app [app_name]
● Running an Application
○ grails run-app
○ grails -Dserver.port=8090 run-app
○ grails r-a
● Testing an Application
○ grails test-app
● Deploying an Application
○ grails war
● Generating an Application
○ grails generate-all [domain]
10. Basic Configuration
For general configuration Grails provides two files:-
● grails-app/conf/BuildConfig.groovy
● grails-app/conf/Config.groovy
Both of them use Groovy’s ConfigSlurper syntax.
BuildConfig :- for settings that are used when running Grails command, such
as compile, run-app etc.
Config :- for settings that are used when your application is running.
Note:- Config.groovy is packaged with your application, but
BuildConfig.groovy is not.
11. foo.bar.hello=”hello”
Note:- the value is a Groovy string literal. The property value can valid Groovy
type, such as strings, integers
foo.bar.hello=’world’
foo.bar.good=”bye”
Both of using same base, the above syntax works but it’s quite verbose and
repetitive.
foo{
bar{
hello=’world’
good=”bye”
}
}
12.
13. Implicit Variable for BuildConfig and Config
Variable Description
userHome Location of Home directory
grailsHome Location of directory where grails is installed.
appName Application Name as it appears in application.properties
appVersion Application Version as it appears in application.properties
14. Implicit Variable for BuildConfig only
Variable Description
grailsVersion The version of Grails used to build the project
grailsSettings An object containing various build related settings, such as baseDir
15. Implicit Variable for Config
Variable Description
grailsApplication The GrailsApplication class instance
16. Environments
1. Grails support the concepts of per environment configuration.
2. The Config, DataSource and BootStrap.groovy files in the grails-app/conf
directory can use per environment configuration.
3. They uses ConfigSlurper
4. Packaging and Running for Different Environments
a. grails [environment] [command_name]
i. grails test war
ii. grails -Dgrails.env=UAT run-app
5. We can detect the environment using the Environment class