Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference a system property within a user-defined .properties file?

I want to define a property for a working directory(say work.dir=/home/username/working-directory), for my production .properties file, without hard-coding the /home/username.

I want to reference the system property user.home in place on the hard-coded /home/username, to make work.dir more generic.

How do I reference the system property and concatenate it will other user-defined strings in a user-defined .properties?

Note: I don't want to access the user.home property in my java code, but from the .properties that I have defined. I want to be able to replace the value of the work.dir with different value for both my production and development(JUnit tests for example).

like image 357
walters Avatar asked Sep 17 '10 16:09

walters


People also ask

Where should I put JNDI properties?

The best way is to add the jndi. properties file to a JAR file and then add it to the class path.

How do I use .properties file?

The Properties file can be used in Java to externalize the configuration and to store the key-value pairs. The Properties. load() method of Properties class is convenient to load . properties file in the form of key-value pairs.

Where is Java system property file?

properties file located in users->appdata->locallow->sun->java>deployment and also directly putting key=value in runtime parameter in java control panel but not working. Edit: We use jeety server for deployment. And we have many properties file bundled with our souce code. What kind of application is it?


1 Answers

You can manage your properties with Commons Configuration and use Variable Interpolation

If you are familiar with Ant or Maven, you have most certainly already encountered the variables (like ${token}) that are automatically expanded when the configuration file is loaded. Commons Configuration supports this feature as well[...]

That would allow a .properties file with

work.dir=${user.home}/working-directory
like image 194
fglez Avatar answered Oct 12 '22 14:10

fglez