Getting Started with Grails and IntelliJ – Part 1

Posted by jt - 12/10/09 at 03:10 pm

For the last few months, I’ve been dabbling with Groovy & Grails in IntelliJ.  Jet Brains has added outstanding support for these languages.  On my Log4Ora open source project, I thought it might be nice to provide some type of web based UI to maintain the database settings.

One of my goals for Log4Ora was to allow you to change log levels on the fly.  I did this by storing the settings for each module in a table. (a module being defined as a package, procedure, function, or trigger)  The initial design I had for this works, but really is awful.  Its not flexible, and violates basic normalization rules.  Its something I’ve been thinking about refactoring.  You can see my original table design here.

Let’s go ahead and refactor this, but we’ll use Grails to help us out.  But before we dive in, you might be wondering why Grails?  Good question.  In a nutshell, Grails gives us a OS and database agnostic web application framework which is designed for rapid application development.  Some people say Grails is just Ruby on Rails, but for Java.  Not exactly.  There are a lot of similarities, but this is not just a Java flavor of ROR.  Grails combines battle proven technologies from Groovy, Spring, Hibernate, and Sitemesh into a comprehensive web application framework.  The dynamic language capabilities of Groovy allows for for things just not possible under pure Java.  Groovy still compiles down to Java byte code, and at the end of the day, you still still produce a standard WAR file which can be deployed to your favorite Java app server.

Ok, enough about Grails, lets get started.  I admit I’m biased to the IntelliJ IDE.  Its a great product & Jet Brains customer support is second to none.  For this series, I will be using examples from IntelliJ.  The first thing we need to do is start a project.  Before you start, I’m assuming that you have Java, IntelliJ, and Grails installed.  If not, please install these before proceeding.

Create Project

Select the option to create a project from scratch, then click next.

From this screen, we’ll use most of the defaults.  Provide a project name and desired path.  Be sure the option for create module is selected & click on “Grails Application”.

New Project 2

IntelliJ will ask you for which Grails SKD to use. Please select the flavor you wish to use for the project.  For this example, we’ll be using version 1.1.1.

Grails SDK

IntelliJ can enable a number of different technologies.   You might be tempted to select the options for Hibernate & Spring since Grails uses these frameworks, but this is necessary.  You’ll have everything you need in the Grails module. Click next, and IntelliJ will build the project structure.

picture-6

After a few moments of running scripts, you will have a new project ready to go.  The image below shows the base project structure.  This is standard for Grails projects.

Grails Project Structure

This was a very quick how-to for getting a Grails project setup in IntelliJ.  Hope you found this helpful.  In my next post, we’ll get started with creating some Domain classes.

Share/Save/Bookmark

Leave a Reply