Reputation: 1947
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
?
Upvotes: 1
Views: 2329
Reputation: 2219
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.
Upvotes: 5