commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <>
Subject Re: [component]commons.configuration.PropertiesConfiguration - load properties from classpath
Date Fri, 09 Jul 2010 20:01:28 GMT
Am 09.07.2010 21:50, schrieb apreg:
> Yeah, you have right. I works, but what if I'd like to put my .properties
> files elsewhere not in the root of my source folder. What should I write in
> the vm arguments to accomplish this and how should  I reference to the
> specified .properties file from code? Sorry if I am on the wrong way.

You have multiple options, but I think the best way is to resolve the 
properties file on your own:

Use Class.getResource() or ClassLoader.getResource() (have a look at the 
Javadocs if necessary) to obtain a URL to the properties file. Then pass 
this URL to PropertiesConfiguration.

For instance, if the properties file lies in the same package as the 
class from which you want to load it, you can do something like the 

URL url = getClass().getResource("");
assert url != null : "Cannot resolve configuration file!";
PropertiesConfiguration config = new PropertiesConfiguration(url);


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message