One year ago, under the gentle pressure of a colleague, I tried Spring Roo. I had mixed feelings about the experience: while wanting to increase productivity was of course a good idea, I had concerned regarding Roo’s intrusiveness. I left it at that, and closed the part of my memory related to it.
Now, one year later, I learned that my favourite web framework, namely Vaadin, had set their sight on a Roo plugin. That was enough for me to get back on my feet and try again. This article tries to describe as honestly as possible the good and the bad of this experience related to both Roo and the Vaadin plugin.
Pure Roo
First of all, I download the free STS 2.5, that includes Roo 1.1.1 and install it.
No problem at this time.
Then, I create a new Spring Roo project inside STS.
Unluckily, STS does not create the default maven directories (src/main-test/java-resources):
errors appear in my Problems tab.
Trying to solve the project, I type the project
command into Roo’s shell inside STS.
Roo complains I should give it my top-level package, though I already did that with the wizard.
OK, I am a nice guy and do as asked:
project --topLevelPackage ch.frankel.blog.roo.vaadin
This time, Roo successfully creates the aforementioned directories as well as a Spring configuration file and a log4j properties file.
Next step is to create my persistence layer. The use of CTRL+SPACE is real nice and helps you much with command parameters. Combined with hint, it’s real easy to get comfortable with Roo.
persistence setup --provider HIBERNATE --database DERBY
Roo nicely updates my Maven POM and let it download the latest version right dependencies (JPA, Hibernate, Derby, etc.). I can always change version if I need a specific one. It even adds JBoss Maven repo so I can download Hibernate. I just need to update my database properties, driver and URL. Uh oh: when I open the file, I see Roo has strangely escaped colons characters with backslash. I just replace the example escaped URL with an unescaped real one.
Meanwhile, I notice an error in the log: "The POM for org.aspectj:aspectjtools:jar:1.6.11.M1 is missing, no dependency information available". Roo updated my POM with version 1.6.11.M1. If I check on repo1, the latest version is 1.6.10. Replacing 1.6.11.M1 with 1.6.10 removes the error.
Now would be a good time to create my first entity:
entity --class ~.entity.Teacher --testAutomatically
STS now complains that the target directory doesn’t exist, like before it complained for source directories.
In order to remedy to that, I just do as before, I launch an instruction.
In this case, I order Roo to launch the tests with the perform test
command.
In turn, Roo launches mvn test
under the hood and Maven does create the target directory.
Entities without fields are useless. Let’s add a first name and a name to our teacher.
field string --fieldName firstName
field string --fieldName name
It would be cool to have courses attached.
entity --class ~.entity.Course --testAutomatically
field string --fieldName name
focus --class Teacher
field set --fieldName courses --type Course
Notice that since Roo works in a contextual manner, I have to use the focus
command so that I do not create the courses Set
inside the Course
class but inside the Teacher
class.
Vaadin plugin
Until now, there was nothing about Vaadin. Here it comes: following the instructions from Vaadin’s wiki, I download the latest Vaadin Roo plugin snapshot and put in in my Roo local OSGI repository. In order to the new bundle to be seen by Roo, I have to restart it which I don’t know how to do inside STS. Instead, I restart STS.
There comes the magic command:
vaadin setup --applicationPackage ~.web --useJpaContainer false`
This command:
- adds the Vaadin dependency
- adds a web directory with images
- updates the POM to war packaging
Yet, when I try to add my new web project to Tomcat, STS complains it doesn’t find candidate projects. The problem lies in that Eclipse is not synchronized with Maven and as such, my project lacks the Web facet. The solution: right-click on my project, go to the Maven menu and click on "Update project configuration" submenu. When done, I can add the project to Tomcat like any other web project (since it is anyway).
Starting Tomcat and going to http://localhost:8080/vaadin, I can see Vaadin handling my request. I just miss the views over my entities, which is done with the following:
vaadin generate all --package ~.web.ui --visuallyComposable true
Conclusion
Well, that was quick, if not perfect. I do miss some features in Roo:
- choice of DAO over ActiveRecord, though Roo has not the same point of view
- a reusable service layer, which is possible with manual effort
- choice of my logging framework
As for the Vaadin plugin, it lacks updating Eclipse files after having changed the POM. Someone not familiar with m2eclipse inner workings could lose some time with this behaviour.
On the other hand, I have a simple webapp in a matter of minutes, that I can now update how I choose.
CTRL+SPACE
and hint
are Roo killer features.
Moreover, like the Vaadin add-on showed, you can add whatever functionality is lacking with your own plugin (or use one already available).
What’s really important for me though, and without it, I wouldn’t even consider using Roo is that it is completely removable in 3 easy steps.
As such you can use Roo’s productivity boost, not tell anyone and remove Roo just before passing your project to the maintenance team.
Thanks to Joonas Lehtinen and Henri Sara for their work on Roo Vaadin’s plugin and sending me ahead of schedule the wiki draft explaining the Vaadin part.
Here are the sources for this article in Maven/STS format.