Reputation: 4357
Does the Apache Commons Configuration library support reading properties/configuration files from the classpath or JAR? I didn't find an API where it can take an InputStream
, that returned by getResourceAsStream
.
Upvotes: 7
Views: 1106
Reputation: 4682
Based on @dkb comment, and since there is not yet an answer to the question, you can do the following:
Configuration configuration = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
PropertiesConfiguration.class)
.configure(new Parameters()
.properties()
.setFileName("app.properties"))
.getConfiguration());
You can also specify the location strategy that you want to use:
Configuration configuration = new FileBasedConfigurationBuilder<FileBasedConfiguration(
PropertiesConfiguration.class)
.configure(
new Parameters()
.properties()
.setLocationStrategy(new ClasspathLocationStrategy())
.setFileName("app.properties"))
.getConfiguration());
Upvotes: 3