Grails: This Time With Tools

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

  1. Prepare the Environment

    • Read the Grails Quick Start, which presents the scenario that we will reproduce in the sections that follow.

    • Download and install the "Web & Java EE" distribution of NetBeans IDE 6.5 Milestone 1 or later. (Everything done below is done with the latest development build, which is probably the best thing to get for getting to know the IDE's Grails support, if you're okay with unexpected errors now and then.)

    • Download and unzip Grails.

    • In the IDE, go to the Options window and set the location of Grails in the "Groovy" panel. If you want to use Groovy, also set the location of Groovy there.

  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:

  3. Create the Domain Class

    Right-click on the Domains classes node:

    Name the domain class "Book" and then fill in the following two lines within the generated class:

    String title
    String author

    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()

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

    You should now see this:

  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 this one:

    def scaffold = Book

    You should now see this:

  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:

There are several other Grails-specific features, such as a Grails shell, support for installing Grails plugins, and menu items for things like Grails stats, upgrade, and WAR-file creation. I will blog about these soon.

Comments:

PS: The above is also available here:

http://www.grails.org/NetBeans+Integration

Posted by Geertjan on July 20, 2008 at 02:41 AM PDT #

thank you !!!

Posted by tattoo on July 20, 2008 at 06:19 PM PDT #

Hi there!

I just checked out Netbeans 6.5 M1 and its Grails support is really nice!

But where can i set the file encoding? I didn't find an option to set project file encoding neither for the way more importent file encoding.

Will it be supported?

Cheers
Sven

Posted by Sven Lange on July 21, 2008 at 09:46 PM PDT #

That works nicely, thx. I did find a problem when stopping and restarting the grails app. The only way I could restart was to first kill off the java process (i.e. Jetty) from the task manager. I presume this is a bug within NetBeans 6.5?

Posted by Chico on July 22, 2008 at 01:10 AM PDT #

I also can't stop or restart Jetty without killing the Java process (Windows XP), so I think it must be a bug.

Did anyone else find that their Bootstrap code didn't get loaded? I couldn't see any errors in my console but my initial list of domain class records was empty.

Posted by nickdos on July 22, 2008 at 02:21 PM PDT #

First off, thanks for the hard work that's gone in to this system. It looks great so far. Am anxious to see strong Groovy/Grails support in Netbeans by default.

I'm having a problem, and I don't know if it's me, a config, or if the support just isn't there yet.

In the example above, you've got a book domain with properties. With that same setup, if I tried to do something with the book, I don't get code completion showing the properties of the book. I also get a box above the code completion stating "unable to find the doc in jdk/gdk".

Do I have a configuration wrong? Or is the support not there for introspecting properties of Grails domain objects? Or am I doing something else wrong?

Thanks!

Posted by Michael Kimsal on July 23, 2008 at 12:03 PM PDT #

That's the main area that's currently being worked on Michael. Should be in good shape in the coming weeks.

Posted by Geertjan on July 23, 2008 at 04:44 PM PDT #

Same problem stopping jetty... otherwise the IDE is really nice, much comfortable than eclipse.

Posted by Pablo on July 23, 2008 at 09:45 PM PDT #

Thanks Geertjan, for confirming that I'm not crazy. Best of luck on this. Is there any way to donate a bit of money to the people working on the Netbeans Groovy/Grails support? I don't see a 'donate' button anywhere, but would love to send a few bucks by way of thanks.

Posted by Michael Kimsal on July 23, 2008 at 11:24 PM PDT #

Is it possible to execute Grails commands like generate-all from Netbeans 6.5 ?

Posted by carol mcdonald on July 28, 2008 at 03:37 AM PDT #

Yes Carol. Create a domain class by right-clicking on the Domain Classes node and then right-click a domain class node and you will see generate-all!

Posted by Geertjan on July 28, 2008 at 03:39 AM PDT #

Michael, thanks for the offer to donate money! Only if you want to donate towards beer would it make sense. If you do, I can promise a pic of the NetBeans/Groovy developers raising a beer in your name! :-)

Posted by Geertjan on July 28, 2008 at 03:44 AM PDT #

Is there a paypal link or someplace to donate? Send me the link and I'll send you a beer... :)

Posted by Michael Kimsal on July 28, 2008 at 12:49 PM PDT #

interesting

Posted by satılık araba on August 02, 2008 at 06:48 PM PDT #

your website sucks. buy u some design dude

Posted by guest on August 04, 2008 at 11:47 PM PDT #

Hi Geertjan,

thanks Geertjan for your instructive post (and as well for including it at http://www.grails.org/NetBeans+Integration).

It was here at your blog that I was able to confirm that Netbeans 6.5 M1 appears to fail when trying to control the Jetty used to run Grails apps. As well service controls are suspiciuosly missing from Jetty within servers page. I trust it'll all be mended in M2 :-)

BTW: If you were to sell ringtones, you might consider revamping your blog. For me, it's the content that counts - keep up your great work!

Regards,
Reiner

Posted by Reiner Saddey on August 12, 2008 at 03:43 AM PDT #

Re "Jetty can't be restarted from NetBeans":

It's not a feature, it's a bug that only occurs with Windows and as yet has not been assigned a milestone: Issue 138116 - Stopping a running app doesn't stop the child process, see http://www.netbeans.org/issues/show_bug.cgi?id=138116

Posted by Reiner Saddey on August 20, 2008 at 06:00 PM PDT #

As a newbie, I am confused by the support for JSF vs Grails in NB 6.5. I would like to use the visual web designer for my grails apps. Can I? If not can I add the Grails framework to a JSF project as you can with Struts or Spring? Thanks

Posted by Sumner Andrews on February 15, 2009 at 02:00 AM PST #

Good

Posted by Taufik Tri Hantoro on April 13, 2009 at 09:39 AM PDT #

Hi, I'm looking for a simple tutorial for grails 1-3.3 and netbeans 6.9. Nothing I find works, including this.
When I run it I get the grails welcome screen, clicking further I get a 404.

Posted by Peter on July 09, 2010 at 08:04 PM PDT #

You're kidding, right? This is a blog entry written 2 years ago,,,

Posted by Geertjan Wielenga on July 09, 2010 at 09:21 PM PDT #

If I have a mySQL DB ready, How do i generate domain classes n controllers from it?

Posted by neo on October 14, 2010 at 12:05 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today