Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(’The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

June 15, 2008

Creating “Hello World” Web Application Using the Grails Framework

Filed under: Groovy/Grails, Web — tabrez @ 4:04 pm

  1. I have covered the installation procedure of Grails framework in my previous posts:
    Setting Up Development Environment For Grails on Windows Vista/XP and GNU/Linux.

    Just to make sure, check out again if the following environment variables are set properly on your operating system.

    On Windows:
    Set Grails environment variables in Windows
    Set Java HOME environment variable in Windows
    Set Groovy HOME environment variable in Windows
    Set Grails HOME environment variable in Windows
    Set Grails PATH environment variables in Windows

    PATH should be set to something like(you can also check with ‘echo %PATH%’ on the command prompt):
    c:\ruby\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin;C:\Program Files (x86)\Subversion\bin;%JAVA_HOME%\bin;%GROOVY_HOME%\bin;%GRAILS_HOME%\bin

    On GNU/Linux:

    # echo $JAVA_HOME :: $GROOVY_HOME :: $GRAILS_HOME
    /usr/lib/jvm/java-6-sun :: /home/tabrez/groovy :: /home/tabrez/grails
    # echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/tabrez/groovy/bin:/home/tabrez/grails/bin
  2. Now you are all set to create Grails applications from the command line using your favourite text editor. IDE integration support for Groovy and Grails is not that great at this moment, I will write more about it in the next post. Let me just walk you through the creation of a sample Grails application from the command line.

    Open the command prompt and run the following commands:

    # grails create-app hello
    [lot of text]
    Created Grails Application at C:\Users\tabrez\grails_apps/hello
    # cd hello && dir
    .classpath
    .project
    application.properties
    build.xml
    grails-app
    hello.launch
    hello.tmproj
    lib
    scripts
    src
    test
    web-app
    # grails create-controller hello
    [lot of text]
    Created ControllerTests for Hello
  3. Open hello/grails-app/controllers/HelloController.groovy using your favourite programming editor/IDE(e.g. SciTE, Emacs, Vim) and change its content to look like this:
    Hello World program in Grails and Groovy
  4. Run the web application and view it in the web browser.
    # grails run-app
    [lot of text]
    Server running. Browse to http://localhost:8080/hello
    2008-06-15 15:55:51.363:/hello:INFO: GSP servlet initialized

    Now our application is running at the specified url. To invoke the controller that we had written earlier(Step 3), open the following url in a web browser:
    http://localhost:8080/hello/hello/hello
    And you should see the following output.
    Grails Hello World program output in Web Browser
    (If you are confused about the url: the first hello is the name of the application, the second hello is the name of the controller and the third hello is the name of the action to be invoked. In non-hello-world applications, these three will be different from each other!)

That’s it. You have created and executed your first Grails web application. Next up is IDE integration.

Resources:
For more information, refer to the following resources:
1. Grails QuickStart Guide
2. Grails Tutorials and Screencasts
3. The Definitive Guide to Grails (Amazon)


If you want to receive future posts by email, enter your email address here:

Related Posts:

  • Setting Up Development Environment For Grails on Windows Vista/XP
  • Setting Up Development Environment For Grails on GNU/Linux
  • Installing Grails in Ubuntu GNU/Linux Using Package Manager
  • “Hello, World” Web Application in Ruby on Rails using Aptana Studio
  • “Hello, World” Web Application using Struts 2 in IntelliJ IDEA 8.0 M1
  • Should I Be Developing Ajax Applications using Google Web Toolkit(GWT)?
  • A Case Against Ajax Web Development Model

  • Readers who viewed this page, also viewed:


    3 Comments »

    1. [...] proceed to the next part of this tutorial and create an example “Hello World” web application using Grails framework to validate your Grails installation on Windows operating [...]

      Quote

      Pingback by Setting Up Development Environment For Grails on Windows Vista/XP — June 19, 2008 @ 5:01 pm

    2. [...] Enlace | Hola Mundo [...]

      Quote

      Pingback by Getting Started with Grails « Ubuntu Life — June 23, 2008 @ 9:08 pm

    3. [...] go to the post that explains how to create a Grails “Hello, World” web application to test if your Grails development environment is properly setup. It is for the Windows platform [...]

      Quote

      Pingback by Setting Up Development Environment For Grails on GNU/Linux — July 10, 2008 @ 2:32 pm

    RSS feed for comments on this post. TrackBack URI

    Leave a comment

    Subscribe without commenting


    Copyright (c) 2006, 2007 Tabrez Iqbal.
    Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


    Powered by WordPress
    This website is hosted by Dreamhost