Hello World Application

Posted by Anantha Narayanan On 10:03 PM 2 comments

Now heading straight to create a fresh application we will create a “Hello World” printing application. Grails creates a main folder and numerous sub-folders for each application. It is easy to create a parent folder which holds all my applications (we will be creating more than one applications in our tutorials). Create a folder c:\grails_applications and use command prompt from now on. Navigate to c:\grails_applications folder in command prompt.

Now we are ready to create our first application. Type grails create-app helloworld in command prompt.

C:\GRAILS_APPLICATONS>grails create-app helloworld

You will get a whole lot of lines of messages about creation of folders. Just ignore them for the time-being. You must have got the final line of message as follows:

Created Grails Application at C:\grails_applications\helloworld

That’s all we want now. Navigate inside helloworld folder. Now execute the following command:

C:\GRAILS_APPLICATONS\HELLOWORLD>grails create-controller hello

Once the controller is created, we are ready to modify the class to display the Hello World text. Use a text-editor and edit the following file:

C:\grails_applications\helloworld\grails-app\controllers\helloworld\HelloController.groovy

The default contents of the file will be like this:

package helloworld

class HelloController {
def index = { }
}

Modify it to look like this:

package helloworld

class HelloController {
def world = {
render "Hello World!"
}
}

Thats all required. Before we can view the results in a browser, we have to start the application. Execute the following command for this:

C:\GRAILS_APPLICATIONS\HELLOWORLD>grails run-app

Once you get the following message, its time to open the web browser.

Server running. Browse to http://localhost:8080/helloworld

Copy/Paste the URL into web browser and you will now be able to access your application. Now click on the link below Available Controllers and you will be able to see the Hello World Message.

Note: In case you are getting error saying that port 8080 is already in use, try the following command and use a different port which is not in use.

C:\GRAILS_APPLICATIONS\HELLOWORLD>grails -Dserver.port=8090 run-app
If you like the tutorial, please leave your valuable comments below.

2 comments:

this is a great way to start with GGCT. 10 out of 10.

Post a Comment

Recommended Post Slide Out For Blogger