commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Bourg <sma...@lfjr.net>
Subject Re: commons configuration: user specified configuration file?
Date Tue, 28 Sep 2004 19:55:05 GMT
Orjan Nygaard Austvold wrote:
> I've tried commons configuration, and I find to quite usable. Good work!

Thanks ! Glad to hear you found it useful :)


> There is one thing I didn't manage to do (or understand how to do). As 
> an example I'm building a test appliction in which there exist a default 
> configuration loaded off the classpath.
> 
> How can I add a configuration file specified by the user, perhaps as an 
> argument on the command line?
> 
>  From what I understand the ConfigurationFactory needs a URL to an XML 
> file containing reference to which configuration files to load. Is this 
> right?

You could use the ConfigurationFactory, but since the user file isn't 
known it's easier to build a CompositeConfiguration directly. It would 
look like this:

CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new 
PropertiesConfiguration("default-config.properties"));
if (userConfig != null) {
     config.addConfiguration(new PropertiesConfiguration(userConfig));
}

Emmanuel Bourg



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message