2

For Apache Commons Configuration, I am trying to load multiple java property files.

I was wondering if it's possible to "import/include" other files in one file so I only need to load the first file and the rest will all be imported.

E.g.

common.properties

include 'specific.properties' propertyA=10 propertyB=20 

specific.properties

propertyC=30 propertyD=40 

So in the end I would have

propertyA=10 propertyB=20 propertyC=30 propertyD=40 

Currently, I'm just using

CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new PropertiesConfiguration("common.properties")); config.addConfiguration(new PropertiesConfiguration("specific.properties")); 

Thanks in advance!

1 Answer 1

1

It is possible. Copied from documentation:

If a property is named "include", and the value of that property is the name of a file on the disk, that file will be included into the configuration.

In your case (common.properties):

include = specific.properties propertyA = 10 propertyB = 20 

specific.properties

propertyC = 30 propertyD = 40 

See here https://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Using_PropertiesConfiguration

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Exactly what i needed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.