Before getting started is always the installation. Designed in the case of Grails, which is relatively simple:
- Download and unpack in a directory
- Set environment variable JAVA_HOME to an existing J2EE installation (version> = 1.4)
this looks like in Windows:
> set JAVA_HOME=C:\\j2sdk1.4.2_02 > set PATH=%PATH%; \\bin> set JAVA_HOME=C:\\j2sdk1.4.2_02 > set PATH=%PATH%; \\bin
It is finished grails is available. With grails help can make all the possible commands and display the same time to determine if grails is installed correctly.
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 the all artifacts from a domain class "install-dojo" - Installs the Dojo toolkit into the current project "test-app" - Run current app's unit tests "run-app" - Run the application locally and wait "create-webtest" - Create the functional test layout "generate-webtest" - Generates a WebTest from a domain class "run-webtest" - Run the functional tests for a running app "war" - Creates a deployable Web Application Archive (WAR) "shell" - Opens the Grails interactive command line shell "console" - Opens the Grails interactive swing console With this knowledge you can now create an application:
> cd > grails create-app ... create-app: [input] Enter application name: usermanagement ... BUILD SUCCESSFUL> cd > grails create-app ... create-app: [input] Enter application name: usermanagement ... BUILD SUCCESSFUL
The application would now have to grails run-app run, but for testing it would be nice, even before entering data query or change, or delete (the so called crud operations). Grails uses, as well as many other web applications, the Model-View-Controller (MVC) design pattern. This means that you need for the model (actual data) classes, by which you can store the data persistently. In Grails, we speak here of the so called domain classes whose basic structure is generated as follows (you can also create manually).
> grails create-domain-class ... create-domain-class: [input] Enter domain class name: user ... After that is located in the \grails-app\domain file User.groovy with the skeleton of the domain - class. Any user who is an object of the domain - is class represents user to the properties.
class User { Long id Long version String firstname String lastname String email Date createdAt } Now we need is a controller that is also based on the Grails domain class (our users) can be generated.
grails generate-all ... input-domain-class: [input] Enter domain class name: user ... After that is located in the \grails-app\controllers file UserController.groovy with the framework of the Controller - class. For testing, we recommend you to the features of Grails scaffolding to fall back, the application generated dynamically at runtime.
class UserController { def scaffold = User } Thanks to the included HypersonicSQL database and servlet container jetty can after stopping the command grails run-app under the url http://localhost:8080/usermanagement/user test their finished web application.
Those who have now seen for the first time in scaffolding action, would prefer to only work with it because it is so beautifully simple and convenient. Unfortunately, German-speaking users, usually begin with some English field names, so this function is reserved for only the forms that the user does not get to see.
In the next post I'll devote myself to the configuration of the database connection.




January 20th, 2009 at 12:11 am
Thank you for the nice tutorial.