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
.
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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.