Groovy & Grails: Creating Your First App

Site Admin · 11 Sep 2026 · 9 views

The Create and Run Cycle

Grails has a command line tool that scaffolds a whole application. From an empty folder you create a project, then start a development server.

grails create-app learnhub
cd learnhub
grails run-app

The first command generates a complete project tree with a build configuration, source folders, and a default layout. run-app starts an embedded server, and by default the app is reachable at http://localhost:8080. Visiting that address shows the Grails welcome page.

Project Structure at a Glance

  • grails-app/controllers - the HTTP entry points.
  • grails-app/domain - the persistence models.
  • grails-app/views - the GSP templates.
  • grails-app/services - business logic.
  • grails-app/conf - configuration files.
  • src/main/groovy - other Groovy sources.

Grails wires these folders together by convention, so you never declare a routing file or a component scan list by hand.

Generate a Controller

Use the generator to build a controller and a view pair quickly.

grails create-controller welcome

grails-app/controllers/learnhub/WelcomeController.groovy

Open the generated file and edit the index action.

class WelcomeController {
    def index() {
        render view: "index", model: [message: "Hello Grails"]
    }
}

The index action renders the index view and passes a model map containing a message string.

See It in the Browser

Save the file and refresh http://localhost:8080/welcome. Grails recompiles changed classes automatically during development, so no restart is needed. You have now run a real framework: a controller mapped to a URL, serving a rendered view with data. If anything looks missing, restart the server or check the log output in the terminal, where Grails prints friendly errors with line numbers for most mistakes. This fast feedback loop is a big reason beginners build confidence quickly with Grails.

Key Points

  • grails create-app scaffolds a full project with all conventions in place.
  • run-app starts a hot-reloading development server on localhost:8080.
  • Controllers, domains, and views live in dedicated convention folders.
  • create-controller generates starter files you can edit straight away.
Share this post:

Comments (0)

Please login or register to comment.