substituting values in property file

A

Andy Fish

Hi,

My app uses a property file for configuration, and I would like to have some
way to substitute other properties (or maybe even environment variables)
when interpreting the properties file. It's probably best illustrated by an
example, instead of:

myapp.logfile = /usr/local/myapp/logs/logfile
myapp.archivedir = /usr/local/myapp/data/archived

we could have something like:

myapp.log.file = ${myapp.installroot}/logs/logfile
myapp.log.file = ${myapp.installroot}/data/archived

This means that I can supply them with a default properties file that will
work wherever they install the application.

Anyone know of a standard way of doing this? I'm sure it would be fairly
easy to subclass java.lang.properties but I don't want to reinvent the
wheel.

Andy
 
H

Harald Hein

Andy Fish said:
This means that I can supply them with a default properties file
that will work wherever they install the application.

Anyone know of a standard way of doing this? I'm sure it would be
fairly easy to subclass java.lang.properties but I don't want to
reinvent the wheel.

I am not sure what you want. Maybe you are after the "default" argument
to the Properties constructor. Check the API documentation. You need to
construct two or more Properties objects. A common setup is to have a
user, system, and an application default properties file. You deliver
the application default properties file. The user can change his user
file (some dot-rc file on unix), and his system administrator can set
local defaults by editing the system properties file.
 
Y

Young Seeker

One way to overcome this problem is using ant scripts.

You can use the parameter substitution in ant script to replace
${myapp.installroot} with a value provided at compile time.

(From the way you have written the example, I guess you already know
this. But just in case.)

Regards,
Young Seeker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top