Sunday July 20, 2008
Grails: This Time With Tools
Here's how to get started with Grails in NetBeans IDE 6.5.
- 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.
- 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:
- 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:
- 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:
- 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.
Jul 20 2008, 08:19:32 AM PDT Permalink
PS: The above is also available here:
http://www.grails.org/NetBeans+Integration
Posted by Geertjan on July 20, 2008 at 09:41 AM 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 22, 2008 at 04:46 AM 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 08: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 09: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 07: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 11:44 PM PDT #
Same problem stopping jetty... otherwise the IDE is really nice, much comfortable than eclipse.
Posted by Pablo on July 24, 2008 at 04:45 AM 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 24, 2008 at 06:24 AM PDT #
Is it possible to execute Grails commands like generate-all from Netbeans 6.5 ?
Posted by carol mcdonald on July 28, 2008 at 10: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 10: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 10: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 07:49 PM PDT #
interesting
Posted by satılık araba on August 03, 2008 at 01:48 AM PDT #
your website sucks. buy u some design dude
Posted by 89.15.87.125 on August 05, 2008 at 06:47 AM 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 10: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 21, 2008 at 01:00 AM PDT #


