Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 870
flow2k Avatar asked Aug 11 '26 19:08

flow2k


1 Answers

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());
like image 181
pringi Avatar answered Aug 14 '26 08:08

pringi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!