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
.
Asked
Active
Viewed 595 times
5

flow2k
- 3,999
- 40
- 55
-
1this will solve your problem, filePath: configLocation ```PropertiesConfiguration propertiesConfiguration = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) .configure(new Parameters() .properties() .setFileName(configLocation) .setListDelimiterHandler(new DefaultListDelimiterHandler(','))) .getConfiguration();``` – dkb Mar 30 '21 at 06:10
1 Answers
2
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());

pringi
- 3,987
- 5
- 35
- 45