Java Properties – Global and local properties

So I’m beginning to use the Java Properties class in order to set key-value pairs for my project. The way I’m designing my project is so that there are default properties which will be created using a config file as well as another config file for either overwriting or adding additional properties. The default config file will be in my Eclipse MainFramework project while the other config file will be in the local project where tests are stored.

MainFramework
Validation
TestProject1
TestProject2

In this example, MainFramework has the default config file and each TestProject may or may not have it’s own local config file. Is there a way to have my desired functionality through Java’s Properties class.

Answer

The java properties object is a Hashtable. If you read the properties for your main configuration file and then read a second properties file into the same object it will override the existing properties if they exist in both places, or add new ones if they don’t already exist. Properties that are only found in the original file will remain as well.

Leave a Reply

Your email address will not be published. Required fields are marked *