Grails Part 1 - Setting up a Project

Click here to view the full tutorial
Continuing series: Developing a Grails Web Application.
This application will use the Grails Framework to develop a web application using:
1. MongoDB
2. Spring Security
3. Apache CXF
4. Jetty Web Server
5. Maven build integration
View Project on Github: Grails MongoDB Demo
These Instructions Will Walk Through:
  • Installing the Grails SDK
  • Project Setup
    1. Creating a Grails Application
    2. Integrating with Maven
    3. Integrating with IntelliJ

Installing the Grails SDK

In this example, we are using Mac OS X. Some adjustments are required for Windows. We will also be integrating with IntelliJ IDE, and using Maven as our build manager. This is the environment we use at Appriss, so I'm trying to make this consistent to that. Personally, I would avoid using Maven in most other circumstances  Grails is well apt at handling dependencies.
Install Grails SDK
  1. Go to the Grails Download Page and install the latest 2.x.x binary
  2. Extract the file to any location, for example: ~/sdks
  3. Add the bin directory to your path
    • Linux/Unix: export GRAILS_HOME=~/sdks/grails-2.x.x
      • Then add the bin directory to you PATH variable: export PATH="$PATH:$GRAILS_HOME/bin
    • Windows: set an environment variable under My Computer/Advanced/Environment Variables
Executing Commands
  1. Open a console
    • The grails commands are used in the manner: grails [command]
    • You can also launch the grails script executor by simply typing grails.
Once you create a Grails project, you can use this console to quickly create domain classes, controllers, or many other Grails components. This will not be neccesary in this demo, since we will be using the IntelliJ Idea 11 IDE

Project Setup

Project setup requires working within a terminal/command window
1. Creating a Grails Application
    $ cd ~/dev/workspaces
    $ grails create-app grails-mongo-demo
2. Integrating with Maven
    $ cd grails-mongo-demo
    $ grails create-pom com.mycompany
    $ mvn compile
The create-pom command expects a group id as an argument. The name and the version are taken from the of the application. The Maven plugin will keep the version in the pom.xml in sync with the version in
Referenced From Grail Docs
3. Integrating with IntelliJ
Integrating is simple!
    $ grails integrate-with --intellij
The last thing to do is open the project in IntelliJ, and thats it! Your ready to get started.A Run configuration should already be available. Click run, and go to http://localhost:8080/grails-mongo-demo/ to view the default layout.

Important Note: When grails creates the Maven POM, it adds a configuration to the plugin; grails-maven-plugin: <fork>true</fork>. If you want to be able to kill run processes from intelliJ, comment out this line.
Continue to Grails Part 2 - Configuring Plugins

View Full Tutorial


Popular posts from this blog

Ignore Header and Trailer Lines During Java InputStream Read

Atmosphere Websockets & Comet with Spring MVC