Create Roo Project

Create Project

Execute the steps below to create a new project, its domain model, sample data, and a user interface.  This is standard Roo functionality, preparing a basic system to which we will then add business logic.

Create Empty Folder (STS Workspace) and start STS

Create a new empty folder, and open STS specifying that as your workspace.  Alter preferences as desired (it is usually a good idea to set Preferences > Run/Debug > Console to unlimited.

Create Roo Project

Right-click on the left view (Package Explorer) to create a new Roo Project:

Specify the project properties on the ensuing dialog:

You now have an empty project.  Observe that STS has opened the Roo Shell; enter the following command to specify your persistence properties:

persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY

The output should be along the lines of:

Create Database Entity

You now have an empty project.  In the Roo Shell, enter the following command:

entity --class ~.domain.Customer

This creates a Java class, including the necessary annotations for JPA persistence:

Create rest of Database model

You can now enter the fields, either using the Roo Shell or in the code editor.  Since we want to focus on business logic and move past the data model, we accelerate this phase:
  1. unpack the file, and 
  2. paste the files into ablroodemo.domain (replace the existing file).
You should now see the following (the Roo Shell illustrates that Roo is creating many related classes for setters/getters, toString and all manner of boilerplate code):

Create Test Data

In the next step, we'll create our user interface, but it will be boring if there is no test data.  Spring/Roo enables you to process events such as system startup, which we'll use to populate our database:
  1. Download the Loader class (attached at the bottom of this page)
  2. Paste it into STS at src/main/java
  3. This may result in a package error - correct by moving to package ablroodemo (see below). The project should be error-free after the correction.

Create User Interface

In the Roo Shell, enter the following command:

controller all --package ~.web

This will generate a number of files.

Test User Interface

To test the generated User Interface, select the Servers view, then Add and Remove...

Then, add BusLogicDemoRoo as shown below

Start the server (click the bug icon on the upper right of the Servers view)

You should then be able to start http://localhost:8080/BusLogicDemoRoo/ in your browser; click List All Customers and you will see loaded (but incorrect - note the Balance is not computed) data:

You now have a simple, but complete, Roo project, including a database schema and a web interface.

We are now ready to introduce business logic.

Val Huber,
Mar 30, 2012, 9:32 PM
Val Huber,
Mar 30, 2012, 9:32 PM