Grails Part 1 - Setting up a Project
Click here to view the full tutorial
Continuing series: Developing a Grails Web Application.View Project on Github: Grails MongoDB Demo
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
These Instructions Will Walk Through:
- Installing the Grails SDK
- Project Setup
- Creating a Grails Application
- Integrating with Maven
- 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
- Go to the Grails Download Page and install the latest 2.x.x binary
- Extract the file to any location, for example:
~/sdks
- Add the bin directory to your path
- Linux/Unix:
export GRAILS_HOME=~/sdks/grails-2.x.x
- Then add the
bin
directory to youPATH
variable:export PATH="$PATH:$GRAILS_HOME/bin
- Then add the
- Windows:
set an environment variable under My Computer/Advanced/Environment Variables
- Linux/Unix:
Executing Commands
- 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
.
- The grails commands are used in the manner:
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 application.properties of the application. The Maven plugin will keep the version in the pom.xml in sync with the version in application.properties.
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
Comments
Post a Comment