1. Motivation
It is almost for a year now, that I'm trying out Java EE. I figured out, that it could be pretty powerful and I was impressed by its possibilities. But I always found it a bit complicate. Particular in my After-Work-Programming-Environment, I got far too little things going.
So I concentrated on looking for a solution easier to use. Grails, which I read a lot about recently, seemed to me worth investigating. Some point that I found pretty intriguing:
- reuse of my Java knowledge
- handy groovy language
- use of (at least for me) new techniques such as dependency injection via built-in-Spring
- well known and approved programming environment NetBeans
- and at last a cheap and hopefully easy-to-use application server provided by Google's app-engine
2. Setting things up
Installing grails and the app-engine-api is plain sailing. First I was a bit concerned using grails 1.2.0 with Google's app-engine, cause I found some misleading information. But as you will see, there's no need to be concerned. Grails 1.2.0 runs on the app-engine.
Notably misleading was the information on top of the documentation to grails appEngine-plug-in that version 1.2 is not supported. Well, now the documentation is updated and there shouldn't be any confusion no more.
On my Ubuntu box, I installed NetBeans from catalog. It's not the most recent version 6.8, but I felt that using 6.7.1 should do it.
There is a nice plug-in for NetBeans supporting grails. It support the grails command and has some auto-completion functionality. Configure the plug-in in the Option -> Miscellaneous -> Groovy menu.
3. Hello World
First, I created a new project in NetBeans. So I chose File -> New Project ... Selected Category "Groovy" and Project "Grails". At last, I named the project "HelloWorld".
To make the app-engine-api available to grails, I edited the file BuildConfig.groovy since I couldn't get the env-variable APPENGINE_HOME to be seen by NetBeans. I added the following line:
Now I installed the app_engine plugin. To do so, I used the Netbeans context menu: right-click on the project, "Run Grails Command...". Then I selected "install-plugin" and "app-engine" as parameter. Version 0.8.5 was selected and installed. You are asked, if you want to install either JPA or JDO support. I decided to use JPA, since I haven't got any experience in JDO so far.
I'm fascinated by Grails GORM, so I wanted to take advantage of this features even when using the app-engine. There is a plug-in, making at least the get, save, delete commands available to the controller. So I installed the "gorm-jpa" plug-in via context menu. Version 0.6 was selected and installed.
There are some needs, to change the configuration, since you don't have access to the file-system when using app-engine. I changed the Config.groovy file:
I created my first domain class: HelloWorld.groovy. Be sure, that you add a package-name, since app-engine only accepts files within a package. A greate advantage of gorm-jpa is, that it enters some example JPA-annotation to the domain class.
The last thing was, that I created the controller classes via scaffolding. I just hit the context menu from the HelloWorld.groovy and hit "Generate all".
I tried to run the application using the Grails command "app-engine run" and visited http://localhost:8080/ to see the result.
4. Null-Pointer-Irritations
The result was, there was no result. The start-up of my app-engine-instance failed due to a weired NullPointerException.
I figured out, that it was caused by the underlying version of Spring. There was an exception in their GenericBeanFactoryAccessor.getBeansWithAnnotation-method, causing the JpaPluginSupport.groovy script to fail. Here's a solution: I copied the source code of GenericBeanFactoryAccessor to the file
I also edited the file
and pasted these lines to line 72:
I reran the "app-engine run" command and checked the localhost. This time, it ran like a charme!
5. Conclusion
The pretty tough part was to get beyond the NullPointerExceptions. The plug-ins seemed to me some kind of unready.
Besides, grails seems from this point the right choice:
- there is a pretty active community providing help and support,
- the gorm-jpa plugin makes database-activity pretty simple,
- scaffolding gives you a simple template for your web-application, and
- grails is so handy.
It will take further investigations. But so far, I give two thumbs up for Grails! :-)
6. Links
NullPointer Irritation solution
No comments:
Post a Comment