Book Image

Spring Roo 1.1 Cookbook

By : Ashish Sarin, Ashish Kumar Sarin, Brian Fitzpatrick
Book Image

Spring Roo 1.1 Cookbook

By: Ashish Sarin, Ashish Kumar Sarin, Brian Fitzpatrick

Overview of this book

Spring Roo is an easy-to-use productivity tool for rapidly developing Java enterprise applications using well-recognized frameworks such as Spring, Hibernate, AspectJ, Spring Web Flow, Spring Security, GWT, and so on. Spring Roo takes care of creating maven-enabled projects, enterprise application architecture based on your choice of technologies, unit/integration tests based on your choice of testing framework, and so on. The bottom line is that if you're using Spring, then you must consider using Spring Roo for increased productivity. Spring Roo 1.1 Cookbook brings together a collection of recipes that demonstrate how the Spring Roo developer tool simplifies rapidly developing enterprise applications using standard technologies/frameworks such as JPA, GWT, Spring, Flex, Spring Web Flow, Spring Security, and so on. It introduces readers to developing enterprise applications for the real world using Spring Roo tool. The book starts off with basic recipes to make readers comfortable with using Spring Roo tool. As the book progresses, readers are introduced to more sophisticated features supported by Spring Roo in the context of a Flight Booking application. In a step-by-step by fashion, each recipe shows how a particular activity is performed, what Spring Roo does when a command is executed, and why it is important in the context of the application being developed. Initially, you make a quick start with using Spring Roo through some simple recipes. Then you learn how Spring Roo simplifies creating the persistence layer of an enterprise application using JPA. You are introduced to the various roo commands to create JPA entities, create relationships between JPA entities, create integration tests using Spring TestContext framework, and so on. Following this, the book shows you how Spring Roo simplifies creating the web layer of an enterprise application using Spring Web MVC, Spring Web Flow, and how to create selenium tests for controller objects. Subsequently, we focus on using Spring-BlazeDS, GWT, JSON, and so on. Spring Roo commands that are used to incorporate e-mail/messaging features into an enterprise application are demonstrated next. Finally, we wrap it up with some miscellaneous recipes that show how to extend Spring Roo via add-ons, incorporate security, create cloud-ready applications, remove Spring Roo from your enterprise application, and so on.
Table of Contents (14 chapters)
Spring Roo 1.1 Cookbook
About the Author
About the Reviewers

Creating application artifacts from Roo script

In some scenarios, you may want to generate complete enterprise application skeleton by feeding a set of Roo commands to Spring Roo from a text file. To address such scenarios Spring Roo provides the script command, which allows you to execute commands contained in a text file. The convention is to name the script file containing commands with a .roo extension.


Roo script is nothing but a text file containing Roo commands. The commands are executed in the order they appear in the text file.

In this recipe, we look at how we can execute the commands contained in a ch01.roo text file that accompanies this book. The ch01.roo file contains commands, which let's you create a fresh flight-app project.

Getting ready

If your Roo shell is still open, then exit it and remove all the files from the C:\roo-cookbook\ch01-recipe directory. Download the ch01.roo file from the book's website and copy it to C:\roo-cookbook\ch01-recipe. Start the Roo shell from the C:\roo-cookbook\ch01-recipe directory.

How to do it...

To create the application skeleton execute the script command, by specifying the file containing Roo commands, as shown here:

roo>script --file ch01.roo --lineNumbers

How it works...

The script command accepts the following arguments:




It is a mandatory argument, which specifies the name of the file that contains Roo commands


It is an optional argument that instructs the Roo shell to print the line numbers of the command being executed from the file

There's more...

One of the features that you will not find in Spring Roo is to revert the execution of a previous command. For instance, if you added a field using the field command and now you want to rollback the changes it made, then it is not possible. If you have mistakenly executed a Roo command, you can remove it from the log.roo file and re-execute the commands in log.roo using the script command.

If a Roo command fails for some reason, it is commented out in the log.roo file. So, you don't need to worry about removing commands that failed execution from your log.roo file.

See also

  • The Setting up Roo recipe show how you can get started with Spring Roo.