Grails Quick Start in NetBeans IDE

Here's how to get started with Grails in NetBeans IDE 6.5 in 5 simple steps.

Step 1: Prepare the Environment

  • Read the official Grails Quick Start, which presents the scenario that we will reproduce in the sections that follow.
  • Download and install the "Java Web & EE" distribution of NetBeans IDE 6.5. Nothing other than that is required, i.e., no plugins. Grails support (and Groovy support) is native to NetBeans IDE 6.5.
  • Download and unzip Grails. Make sure it works from the command line (i.e., run "grails" on the command line).
  • In the IDE, go to the Options window, Miscellaneous and set the location of Grails in the "Groovy" panel. If using OS X then Miscellaneous can be found under NetBeans Preferences.

Step 2: Create the Application

  • Choose the Grails Application project in the New Project wizard (Ctrl-Shift-N):

  • Click Next and type the name of the project:

  • Click Finish and you should see this:

  • Expand the folders and have a look around:

  • Also look at the generated files and notice that many of them have default values filled in:
\

Step 3: Create the Domain Class

  • Right-click on the Domain classes node:

  • Name the domain class "Book" and then fill in two Strings, "title" and "author", in the generated class. You should now see this:

  • Create some initial values in the Bootstrap.groovy class:
new Book(author:"Stephen King",title:"The Shining").save()
new Book(author:"James Patterson",title:"Along Came a Spider").save()

You should now see this:


  • Use Ctrl-Space to call up code completion and then have a look at the other ways of completing the statements above:

Step 4: Create the Controller

  • Right-click the Controllers node:

  • Type "Book" and notice that you are shown that the generated class will be called "BookController":

  • Then comment out the one line generated within the braces and add "def scaffold = Book". You should now see this:

Step 5: Run the Application

  • Right-click the application and choose "Run". The application is deployed to Jetty, as you can see in the Services window:

  • The URL is printed to the Output window. Paste it into a browser and then you'll see your application. Click the "BookController" link and you'll see this:

  • Click New Book and then create a new entry:

  • When you click Create, note that you can edit or delete the entry:

  • ...and that the entry is reflected in the list of entries:


Congratulations! You've completed your first Grails application in NetBeans IDE. NetBeans IDE also supports syntax coloring and other related features for Groovy files and GSP files, as well as the ability to install Grails plugins. You can also use the Grails shell and you can run menu items that call the Grails tasks for creating WARs, creating stats, and upgrading Grails. You can also open existing Grails projects without needing to do anything special, i.e., no import process and no NetBeans-specific metadata is added to Grails projects in order to open them or to work with them.

6 Comments

  • Gravatar
    NetBeans 6.5 is the best IDE I've found for Grails yet. Hopefully 6.7 will continue to build on the excellent built-in support for Grails, Ruby and other languages.
    Apr 04, 2009 18:04 PM marlinspike
  • Gravatar
    Muito bom! incrivel o grails no NetBeans Muito mais facil e mais rapido que no eclipse.
    Apr 16, 2009 17:04 PM Flávio Henrique
  • Gravatar
    Wow Never thought of starting with Grails via NetBeans is so easy.....
    May 05, 2009 15:05 PM icsrdc123
  • Gravatar
    Nice… But: How do I import pre-Existing Grails projects into NetBeans? How do I create a plugin from within NetBeans? Is there a way to make use of other Grails commands from NetBeans? How about commands that are part of plugins installed in a NetBeans Grails project? Is there an easy way to do these things too?
    May 30, 2009 17:05 PM Myles
  • Gravatar
    Furthermore, although I've managed to import a plugin project into NetBeans (as an Eclipse project - whatever), I can't seem to find a way to edit the xxxGrailsPlugin.groovy file as a part of the plugin project.
    May 31, 2009 10:05 AM Myles
  • Gravatar
    How can I do to create a full qualified domain class with NetBeans 6.5? I can't do it for a domain class within a package like: com.ramzi.Users

    Thanks

    Jun 10, 2009 04:06 AM ramzi

Post a Comment