Discovering Roo
I decided to follow along with the presentation given by Ben Alex during the SpringOne Keynote Address by Rod Johnson.
First – I have to install Roo and get the Roo shell up and running. I’m really excited at this point because Roo does look really cool – really RAD!
So I download Roo and explode it out to where I explode all of my 3rd party tools and then open cygwin (I’m on Windows and am trying hard to move away from Dos…) and navigate to the new directory. I find a bin directory with two scripts in it: roo.bat and roo.sh. Sweet! They have a linux version ( cygwin == linux in many ways ). So I run roo.sh and get:
./roo.sh
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/roo/bootstrap/Bootstrap
Caused by: java.lang.ClassNotFoundException: org.springframework.roo.bootstrap.Bootstrap
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: org.springframework.roo.bootstrap.Bootstrap. Program will exit.
OK – take a step back. What have I done wrong here.
I back up a directory and also try ./bin/roo.sh. I look in the readme.txt and create the symlink for install on linux that they recommend:
ln -s /path/to/roo/bin/roo.sh /usr/bin/roo
I type in ‘roo’ and get the same BootStrap Exception.
So then I invoke the wisdom of Google and learn that most everyone who encounters this error gets it because they are in Dos and are working in a different drive than where Roo is installed. I’m on the same drive – but it’s not working in cygwin! No hits on this somehow?!? I find some other results which want me to additionally set an environment variable ROO_HOME. I do this by running from the Roo install directory ( above bin, that is…):
export ROO_HOME=`pwd`
env | grep ROO
I still get the same problem (ClassNotFoundException: org.springframework.roo.bootstrap.Bootstrap), so I cave and go into a Dos prompt. Well, first I add %ROO_HOME%\bin to my path, and *then* go into a Dos prompt. I run ‘roo’ and get the same Bootstrap Exception again. But now, I am on the wrong drive, and cd to the same drive I installed Roo on – now things are working.
Time to even start using Roo in this example : 15 minutes
So, Roo is working now – I have a shell up and running. I’m stoked because it really is cool. It has ‘hint’ as a keyword and tab-based auto-completion which is contextual – it auto-completes the correct things at the correct times.
Creating a project with Roo is a very nice experience : 3 minutes
I already have maven2 installed so I’m able to exit out of Roo and run ‘mvn eclipse:eclipse’ and import the project into Eclipse : 2 minutes
Wow, now we’re flying. Except, wait, there a bunch of “.aj” files in my project. Cool, Roo is leveraging AspectJ. Suck, I don’t have AJDT plugin configured for Eclipse and I’m missing a bunch of the stuff Roo has added to my project ( 9 .aj files in all ). Thinking this might not matter, I run the JUnitTest that Roo created for my project and see only 1 test being run – the demo has a bunch of tests being run ( added via AspectJ ). Also, when I auto-complete on my entity class I created, I don’t get any of the framework added static methods. Translation: I need to install the AJDT plugin for Eclipse: 10 minutes ( http://download.eclipse.org/tools/ajdt/34/update ).
Now things are good to go – I now see the out-of-the box static methods added to my domain class ( Choice.java ). And now when I run the JUnitTest I see that 8 new tests have been added and run. But there’s something else stinky in the state of Denmark!
IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?
No, the SpringAspects JAR is *NOT* configured as an AJC/AJDT aspects library! I don’t know what the SpringAspects JAR is nor what it means to configure it as an AJC/AJDT aspects library. Basically, this means you need to select the spring-aspects.jar to be in the Aspect Path of the AspectJ Build configuration of the project. A picture is worth a 1,000 words here

Adding spring-aspects.jar to AspectJ Build path
10 minutes
So, we’re up to 40 minutes of time spent when the whole thing up until now should only be 5 minutes.
But wait, there’s more. Now I find that I don’t have setters being woven into my Choice.java class by the Choice_Roo_Javabean.aj aspect. I see the correct code in the aspect, but Eclipse’s autocomplete and the actual compilation fail when I attempt to access new Choice().setNamingChoice(). I can deal with this later because I’ve got to get on with the demo.
Next up – Roo will automatically update the companion aspect files it creates as new properties are added to the domain entity. That is, if I simply add a new property called ‘description’ to my entity, and I have roo running in the background, then the Choice_Roo_Javabean.aj is automatically updated with the new getter/setter methods, and the Choice_Roo_ToString.aj is updated to include description. SUPER COOL.
On a tangent, it is not mandatory that these woven aspects dictate the toString and javabean parts of the entity class. The class has annotations in it to specify that the framework will handle these concerns: @RooJavaBean, @RooToString. There is also a @RooEntity which adds all of the dao-ish methods to the class. This is a pattern taken from Grails.
At this point we have an autogenerated JavaBean and a companion TestCase that works.
What about the webapp? Inside of Roo shell, we can now run:
new controller automatic
With a few arguments to generate the framework jsps, the wiring, the formBackingObject functionality and even the crud forms for the domain entity. The ordering of the fields on the crud forms matches the order in which they appear in the java file. Changing the order of properties in the java file will change their order in the ToString.aj and crud JSPs as well. 2 minutes




