18 abr 2012

Maven multi-module projects with Spring Roo and Eclipse/STS

Last week, we started a new project that really fits Maven's multi-module approach. We also decide to give Spring Roo a try in a (quite) large project. We've succesfully used Spring Roo for quick prototyping and small projects, and we found it is a really helpfull and flexible tool.

The hell began when we started our new Maven multi-module using Roo and Eclipse. We used STS support to create a new Roo project and then create some Maven modules... and Eclipse just didn't like the way we did it: Spring Roo shell in STS just stopped working and Roo didn't update, delete or create the AspectJ ITDs.

We googled for a while and found several threads at Stack Overflow and a really nice post explaining some issues and their workarounds.

In short, the working recipe is as follows:
  1. Create your parent project using the command-line Roo Shell (remember to open the Roo shell in an newly created project directory).
  2. Create your modules using command-line Roo Shell.
  3. Create at least one Java class for each Java project before importing to Eclipse/STS.
  4. Copy the project to your workspace folder and import projects to Eclipse/STS using m2e plugin features: "Import->Maven->Existing Maven Projects" from your file system or check-in your project into your SCM and use "Import->Maven->Check out Maven Project from SCM". Be sure to import the parent folder, all the modules should be detected and the Roo Shell for the parent project should automatically open. We never check-in our Eclipse project config files into SCM.
  5. If you want to work with the STS embedded Roo Shell, use only the parent project shell and Roo's module commands to deal with modules. Just remember to keep the project and the shell open if you want Roo to be working with you :)
  6. Remember to use Eclipse's resource filter and working set features to easilly manage all your projects.
If you follow this recipe, you should have no problems at all.

Here, you can download a Roo script sample to create a multi-module project that you can later import into Eclipse/STS.

This demo project consists of a parent demo project and two modules demo-core and demo-web, and uses JPA, Hibernate, PostgreSQL and JSF2/MyFaces/PrimeFaces. Update your JPA, database and/or web layer to fit your requirements.

This demo has been tested on Spring Roo 1.2.1, STS 2.9.1, Maven 3.0.3

project --projectName demo-parent --topLevelPackage es.abacor.demo --packaging POM --java 6

module create --moduleName demo-core --topLevelPackage es.abacor.demo --java 6 --parent es.abacor.demo:demo-parent:0.1.0.BUILD-SNAPSHOT
jpa setup --provider HIBERNATE --database POSTGRES --hostName localhost --databaseName demo --userName demo --password demo
entity jpa --class es.abacor.demo.foo.Foo

module focus --moduleName ~

module create --moduleName demo-web --topLevelPackage es.abacor.demo.web --java 6 --parent es.abacor.demo:demo-parent:0.1.0.BUILD-SNAPSHOT
web jsf setup --implementation APACHE_MYFACES --library PRIMEFACES
web jsf all --package es.abacor.demo.jsf
module focus --moduleName ~

1 comentario:

Anónimo dijo...

thanks very much! worked great.