'Apache Commons Configuration: read from classpath/JAR?
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
.
Solution 1:[1]
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());
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | pringi |