Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1

Existing Groovy DSLs


[ 224 ]

Grails programmers use GORM classes as a mini language for describing the
persistent objects in their application. In this section, we will do a whistle-stop tour
of the features of Grails. This won't be a tutorial on building Grails applications,
as the subject is too big to be covered here. Our main focus will be on how GORM
implements its object model in the domain classes.


Grails quick start


Before we proceed, we need to install Grails and get a basic app installation up and
running. We can use GVMTool to install Grails. Once it has been installed, navigate
to a workspace directory and issue the grails create-app command:


$gvm install grails 3.0.0.RC3$cd ~/workspace


$grails create-app GroovyDSL


cd GroovyDSL


grails run-app


This builds a Grails application tree called GroovyDSL under your current workspace
directory. If we now navigate to this directory, we can launch the Grails app. By
default, the app will display a welcome page at http://localhost:8080.


The example code already has a GroovyDSL Grails app created in the
GroovyDSL subdirectory.

The grails-app directory


The GroovyDSL application that we built earlier has a grails-app subdirectory,
which is where the application source files for our application will reside. We only
need to concern ourselves with the grails-app/domain directory for this discussion,
but it's worth understanding a little about some of the other important directories:



  • grails-app/conf: This is where the Grails configuration files reside.

  • grails-app/controllers: Grails uses a Model View Controller (MVC)
    architecture. The controller directory will contain the Groovy controller code
    for our UIs.

  • grails-app/domain: This is where Grails stores the GORM model classes of
    the application.

  • grails-app/services: Any classes found here will be assumed to be
    service beans.

  • grails-app/view: This is where the Groovy Server Pages (GSPs), the Grails
    equivalent to JSPs are stored.


http://www.ebook3000.com
Free download pdf