-
Book Overview & Buying
-
Table Of Contents
Spring Roo 1.1 Cookbook
In this recipe, we look at Roo commands, which you can use to add, remove, and modify properties defined in a properties file. We will use the log4j.properties file of the flight-app project to demonstrate the use of commands.
The following table shows the properties that we will add, modify, and remove from the log4j.properties file:
|
Property |
Action |
|---|---|
|
|
Modified to |
|
|
Modified to |
|
|
Removed from |
|
|
Added to |
Start the Roo shell from the C:\roo-cookbook\ch01-recipe directory, which contains the flight-app Roo project.
To manage the properties defined in a properties file follow the given steps:
The properties set command is used to modify properties shown as follows:
roo> properties set --name log4j.properties --path SRC_MAIN_RESOURCES --key log4j.appender.R.File --value flightapp.log ..... roo> properties set --name log4j.properties --path SRC_MAIN_RESOURCES --key log4j.rootLogger --value ERROR
The properties remove command is used to remove properties, shown as follows:
roo> properties remove --name log4j.properties --path SRC_MAIN_RESOURCES --key log4j.appender.stdout
The properties set can also be used to add a new property, shown as follows:
roo> properties set --name log4j.properties --path SRC_MAIN_RESOURCES --key log4j.logger.sample.roo.flightapp.service --value DEBUG
Like the properties list command, the properties set and properties remove commands are provided by Properties file add-on
. The following table describes the arguments that both the properties set and properties remove commands accept:
|
Argument |
Purpose |
|---|---|
|
|
It is a mandatory argument that identifies a path to the properties file. Refer to the Viewing properties defined in a properties file and Creating a Roo project recipes for details on the values it can accept. |
|
|
It is a mandatory argument that specifies the name of the properties file whose property you want to remove |
|
|
It is a mandatory argument that specifies the key of the property that you want to remove from the properties file. |
The properties set command accepts all the arguments that the properties remove command accepts. Additionally, it accepts a mandatory argument, value, which specifies a value of the property being set by the properties set command. If a matching property is found in the properties file, the existing property is updated with the new value. If no matching property is found, a new property is added to the properties file.
You can also change the properties file using your favorite IDE. If you are creating a new Roo project which acts as a template for creating other projects, using properties commands to add, modify, and remove properties from a properties file can be valuable.
If you want to modify logging configuration, you should first consider using the logging setup command (explained earlier in the Configuring logging recipe). If you want to modify database properties, you should use database commands (explained in the Managing database configuration properties recipe in Chapter 2, Persisting Objects Using JPA).
The Configuring logging recipe explains how to configure logging using Spring Roo commands
The Managing database configuration properties recipe explains how to configure database properties using Spring Roo commands
Change the font size
Change margin width
Change background colour