Home > Grails > Getting Started with Grails

Getting Started with Grails

Groovy provides a highly-expressive and fully object-oriented language for building Grails applications. Groovy allows the developer to convey ideas concisely and naturally, in a manner that’s easy to read and understand. And, Java developers will appreciate its familiar syntax and its seamless Java integration, knowing that they can invoke any Java class from within Groovy, and vice versa.

Installing Grails

1) Download Grails from following URL.

http://grails.org/Download

2) Grails Installation

  • Extract the archive into an appropriate location; typically C:\grails on Windows.
  • Create a GRAILS_HOME environment variable that points to the path where you extracted the archive (eg C:\grails on Windows)
  • If you have not set the JAVA_HOME environment variable yet, create JAVA_HOME environment variable that points to the path where you have installed Java
  • Append a reference to the “bin” directory within the Grails directory to your PATH variable (eg %GRAILS_HOME%\bin on Windows).
  • Type “grails” at the command line, if a help message is displayed you are ready to start using Grails!

3) Grails Command-Line Help

>grails

help:
Usage: grails [target]
Targets:

“create-app” – Create a new grails app
“create-controller” – Create a new controller
“create-service” – Create a new service
“create-domain-class” – Create a new domain class
“create-taglib” – Create a new tag library class
“create-test-suite” – Create a new test suite
“create-job” – Create a quartz scheduled job
“generate-controller” – Generates a controller from a domain class
“generate-views” – Generates the views from a domain class
“generate-all” – Generates all artifacts from a domain class
“test-app” – Run current app’s unit tests
“run-app” – Run the application locally and wait
“create-webtest” – Create the functional test layout
“run-webtest” – Run the functional tests for a running app
“shell” – Opens the Grails interactive command line shell
“console” – Opens the Grails interactive swing console
“war” – Create a deployable Web Application Archive (WAR

4) Create “Hello World!” Application

So let’s get started creating our first Grails application. To complete your journey through
creating a “Hello World!” application you’re going to step through the following tasks:

  • Execute the grails create-app command to create a basic Grails application.
  • Create something called a controller that will handle a web request.
  • Use the controller to display some text.
  • Run the Grails application and view what you achieved in a web browser.

5) To create our “hello” application we need to run the create-app target. This will prompt
you for the name of the application you wish to create. Enter the word hello and hit the return.

>grails create-app
init-props:
create-app:
[input] Enter application name:
hello

Upon completion, the target will have created the “hello” Grails application and the
necessary directory structure.

Grails Directory Structure

6)  start the Grails application by running the following target

run-app

7)  Run application in the browser.

http://localhost:8080/hello

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.