oblac / jodd

Jodd! Lightweight. Java. Zero dependencies. Use what you like.
https://jodd.org
BSD 2-Clause "Simplified" License
4.06k stars 723 forks source link

Load and merge multiple properties files #753

Closed stodge closed 4 years ago

stodge commented 4 years ago

I've browsed the props documentation and Javadocs but I don't think this is supported. I'm looking to re-write my service's configuration loader and Jodd popped up onto my radar. One thing my current loader does is it loads multiple YAML files (I'm not tied to YAML) and merges them so that the data from all files can be accessed as one.

This might be a good addition to Jodd props. I suppose the API could be:

load(String[] filenames)

or load(File[] files)

Jodd would load them all - my current loader loads 5 or 6 files, each with 10 lines or less.

The API would still work as before, but you would be pulling data from the merged configuration:

    Props p = new Props();
    p.load(new File[] { new File("example.props"), new File("example2.props") } );
    ...
    String story = p.getValue("story");

Cheers

stodge commented 4 years ago

Wait a minute! Is this already supported? I need to try it out. The answer might be in the code example I posted above:

    Props p = new Props();
    p.load(new File("example.props"));
    p.load(new File("example2.props"));
    String story = p.getValue("story");

This is how it works?

stodge commented 4 years ago

Ok, I created a test app and this functionality already exists. I didn't realise (lack of caffeine) that the "..." in the documentation meant I could load multiple files. My bad.

igr commented 4 years ago

Hey @stodge no worries, I should make that more clear :)

stodge commented 4 years ago

No worries - I wasn't thinking straight. Maybe the doc could show two files being loaded, just for idiots like me. :)