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:
oo-cookbookch01-recipe
directory, which contains the flight-app
Roo project.
To manage the properties defined in a properties file follow the given steps:
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
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
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:
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).
3.144.172.38