Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Spring Roo 1.1 Cookbook

You're reading from   Spring Roo 1.1 Cookbook Over 60 recipes to help you speed up the development of your Java web applications using the Spring Roo development tool

Arrow left icon
Product type Paperback
Published in Sep 2011
Publisher Packt
ISBN-13 9781849514583
Length 460 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (14) Chapters Close

Spring Roo 1.1 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with Spring Roo 2. Persisting Objects Using JPA FREE CHAPTER 3. Advanced JPA Support in Spring Roo 4. Web Application Development with Spring Web MVC 5. Web Application Development with GWT, Flex, and Spring Web Flow 6. Emailing, Messaging, Spring Security, Solr, and GAE 7. Developing Add-ons and Removing Roo from Projects Index

Managing properties defined in a properties file


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

log4j.appender.R.File = application.log

Modified to log4j.appender.R.File = flightapp.log

log4j.rootLogger = debug, stdout

Modified to log4j.rootLogger = ERROR

log4j.appender.stdout = org.apache.log4j.ConsoleAppender

Removed from log4j.properties

log4j.logger.sample.roo.flightapp.service = ERROR

Added to log4j.properties

Getting ready

Start the Roo shell from the C:\roo-cookbook\ch01-recipe directory, which contains the flight-app Roo project.

How to do it...

To manage the properties defined in a properties file follow the given steps:

  1. 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
    
  2. 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
    
  3. 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
    

How it works...

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

path

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.

name

It is a mandatory argument that specifies the name of the properties file whose property you want to remove

key

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.

There's more...

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).

See also

  • 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

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image