1

The ideal way to populate a java.util.Properties object seems to be by using some variation on

properties.load(ClassLoader.getSystemClassLoader().getResourcesAsStream(String className));

The big idea being to point Properties.load at a InputStream of a class, rather than at a path.

How can this be done using org.apache.commons.configuration.Configuration?

brandones
  • 1,847
  • 2
  • 18
  • 36

1 Answers1

5

The constructors of the different containers (e.g. org.apache.commons.configuration.PropertiesConfiguration and org.apache.commons.configuration.XMLPropertiesConfiguration) internally take care of this if you pass them a String. They internally use the API in org.apache.commons.configuration.ConfigurationUtils to try and find the resource in the user home directory, the current classpath and the system classpath.

Incidentally, you might find this article useful when trying to figure out the "correct" class loader to use when loading properties files from the classpath.

smooth reggae
  • 2,189
  • 13
  • 14