commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorsten Scherler <thorsten.scherler....@juntadeandalucia.es>
Subject Re: [Configuration]: Classpath resource in composite configuration
Date Thu, 21 Feb 2008 08:05:35 GMT
On Thu, 2008-02-21 at 07:50 +0000, uma_rk@comcast.net wrote:
> The following setup does not work - I was a bit disappointed.
> If I load the configuration definition file off the classpath
> as follows
> 
>    ConfigurationFactory factory = new ConfigurationFactory();
>    URL configURL = new File("config.xml").toURL();

Hmm, not sure but you need to define the location better. As in:
URL configURL = new URL("classpath://config.xml");

...but actually I have not tested this but I reckon you get my point.

salu2


>    factory.setConfigurationFileName(configURL.toString());
> 
> and if the members of "config.xml" are presnet in the classpath:
> 
>        <configuration>
>            <properties fileName="usergui.properties"/>
>            <xml fileName="gui.xml"/>                               /** In classpath
**/
>       </configuration>
> 
> it fails to find and load gui.xml; it yields a NullPointerException.
> 
> Am I doing something wrong or is this indeed a limitation
> of commons config?
> 
> Tx,
> 
> /U
>  -------------- Original message ----------------------
> From: uma_rk@comcast.net
> > 
> > Guten Tag!
> > 
> > Thanks for the prompt response. I am using ver 1.5 - I mistakenly thought
> > I was using ver 1.2.
> > 
> > Are you saying that if I load the following config defn file
> > 
> >    <configuration>
> >       <properties fileName="usergui.properties"/>
> >       <xml fileName="gui.xml"/>
> >    </configuration>
> > 
> > and if gui.xml can be found in classpath, would 
> > ConfigurationFactory.getFactory()
> > automatically load gui.xml?
> > 
> > Further, what is the precedence of loading? If gui.xml is found in classpath as

> > well
> > as in the filesystem path, would classpath take precedence?
> > 
> > Vielen Dank!
> > 
> > /U
> > 
> > 
> > 
> >  -------------- Original message ----------------------
> > From: Oliver Heger <oliver.heger@oliver-heger.de>
> > > uma_rk@comcast.net schrieb:
> > > > I am using commons configuration ver. 1.2.
> > > > 
> > > > I would like ot define a composite configuration in which 
> > > > one or more items are classpath resources as in:
> > > > 
> > > >   <configuration>
> > > >       <properties fileName="usergui.properties"/>
> > > >       <xml fileName="classpath:/gui.xml"/>
> > > >   </configuration>
> > > > 
> > > > Is this somehow possible? Even if the syntax above is not supported, 
> > > > how can I accomplish the same result alternatively? That is,
> > > > I would like to create a composite configuration in which one or more
> > > > resources are loaded off the classpath.
> > > > 
> > > > Thanks,
> > > > 
> > > > /U
> > > > 
> > > 
> > > In recent versions of commons configuration the class path is 
> > > automatically searched for configuration files. I am not sure whether 
> > > this is true for 1.2. (I guess there is a reason why you have to use 
> > > this old version.)
> > > 
> > > What probably will work is to load the configuration definition file 
> > > itself from the class path and specify relative paths to the 
> > > configuration files to be loaded. If the application is correctly 
> > > packaged, the files should be found.
> > > 
> > > There is also some information available at [1].
> > > 
> > > HTH
> > > Oliver
> > > 
> > > [1] 
> > > 
> > http://commons.apache.org/configuration/userguide-1.2/howto_configurationfactory
> > > .html
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> > > For additional commands, e-mail: user-help@commons.apache.org
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> > For additional commands, e-mail: user-help@commons.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
-- 
Thorsten Scherler                                 thorsten.at.apache.org
Open Source Java                      consulting, training and solutions


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


Mime
View raw message