Tuesday, September 6, 2011

Spring Roo 1.2.0 with GWT and Google App Engine

I was first introduced to Spring Roo at Google IO 2010 and I was amazed with the product, it allowed a developer to prototype an application very quickly, building everything from the server, domain, and GWT client.  It looked awesome.

When I got home I realised that we were shown a fixed demo in that many of the features didn't really work when building on Google App Engine and Google Web Toolkit.  Not a problem as all developers know we are used to living on the cutting alpha-beta edge of software where great new features come with one huge caveat, they occasionally don't work.

That was then and this is now.  Like Sushi which I try every 6 months just to confirm that I still am not a huge fan, it doesn't taste of anything right?, I try the latest version of Spring Roo.

The Upgrade Path
Let me just say that I love SpringSource they provide a lot of excellent tools for the Java developer and the Spring Roo documentation is no exception.  The upgrade path is very easy, unpack the latest Spring Roo to a directory of your choosing, amend your $ROO_HOME variable in .profile (Mac OSx) and then re-establish the symbolic link to the roo command line.  (sudo ln -s $ROO_HOME/bin/roo.sh /usr/bin/roo)

Done and done!

The Bleeding Edge
So I tried Spring Roo 1.1.5 and it was giving me lots of errors with trying a GWT-GAE project.  It seemed as equally unreliable as I had tried with previous versions.  Let me just add if you are using a standard database such as MySQL or any of the other persistence options, I believe Spring Roo works just fine.  The problems I usually run into are related to the peculiarities of Google App Engine and how Roo handles those.

Since most of my current projects are currently in the GAE-GWT sphere and Roo advertises that it is suppose to work in this area, I decided to upgrade to the very latest Spring Roo, so I delved into the nightly builds and installed (1.2.0.BUILD-SNAPSHOT [rev 176e407]).

Go for 1.2.0 Its Much Better
After building a couple of projects with 1.2.0 I can honestly say this is the best version yet by far.  Why?  Well it appears to work this time for GWT-GAE projects.  Most of my personal work is done on Google App Engine.  This might change as I am not really liking the new billing restrictions but we will see how those actually plan out when implemented.

I typically build small projects that utilise some sort of reference between domain objects and then build a GWT project and then test it to see if it actually works.  I will deal with deployment in a different post.  What is great about Roo is that you can amend say the domain objects and the auto UI will get updated automatically.  Simply add the line : private String userName; : to your domain object, boot up Roo and it auto creates the UI amendments needed.  Pretty stunning.  I haven't yet got to work out how you prevent it from doing this should you want to improve the UI, but I am sure that will come soon.

The project I have built it is that for a taxi company to take bookings.  It includes three domain objects Contact, Booking and Journey.    A booking can have one or more contacts, and one ore more journeys.

A Spring Roo GAE GWT project that works
 Here is the contents of my Roo file, hopefully this will help you work with your project.

project com.prestige.booking

persistence setup --provider DATANUCLEUS --database GOOGLE_APP_ENGINE --applicationId PrestigeBooking

enum type --class ~.shared.domain.ContactType
enum constant --name Booking
enum constant --name Billing
enum constant --name Passenger

entity --class ~.shared.domain.Contact  --testAutomatically 
field string --fieldName fullName --notNull
field string --fieldName email
field string --fieldName phoneNumber
field enum --fieldName contactType --type ~.shared.domain.ContactType

entity --class ~.shared.domain.Booking --testAutomatically 
field reference --type ~.shared.domain.Contact passenger

entity --class com.prestige.booking.shared.domain.Journey --testAutomatically 
field date --fieldName journeyDate --type java.util.Date 
field string --fieldName startAddress 
field string --fieldName endAddress
field string --fieldName startTime 
field reference --fieldName booking --type com.prestige.booking.shared.domain.Booking 

loggin setup --level INFO

web gwt setup


Next Steps
If you have used Roo or have done some interesting things with a Roo project please get in contact.  I have yet to explore the AddOns or detailed more information on the workflow in a Roo project that goes from prototyping to real world application.  Get in contact and lets document some Best Practices for this awesome product.

1 comment:

  1. Did you run gwt:run after this? This is failing for me..

    ReplyDelete