Work of Art
Work of Art

Reputation: 53

Apache Commons Configuration file import files

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!

Upvotes: 2

Views: 1024

Answers (1)

Justas
Justas

Reputation: 811

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

Upvotes: 1

Related Questions