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).
The best way is to add the jndi. properties file to a JAR file and then add it to the class path.
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.
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With