commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@t-online.de>
Subject Re: Commons Configuration Problem
Date Wed, 02 Mar 2005 20:41:17 GMT
If I understand you correctly, you don't get an exception, but you 
cannot access your properties, i.e. your configuration is empty.

I would guess that the problem lies in your configuration definition 
file PLConfig.xml. Make sure that it has the correct format. The root 
element must be named <configuration>. Below that there can be elements 
that load configuration sources like <properties> or <xml>.

A source for working examples can be the unit tests. The test class for 
ConfigurationFactory loads multiple files from different sources.

HTH
Oliver

Charles Griswold wrote:

> I am trying to set up the Commons Configration facility.  It seems 
> like no matter what I do
> I can't get it to read the configuration file. What is particuarly 
> confusing is that I had it working after a fashion and now it doesn't
> My code looks like:
> ========================================================================== 
>
> private void getConfig(String name) throws Exception {
>        try {
>            ConfigurationFactory factory = new ConfigurationFactory();
>            File ft = new File(name);
>            if (!ft.exists() ) {
>                logger.fatal("PlanLogix - Error Configuration file: 
> "+name+" Missing. Execution halted");
>            }
>            factory.setConfigurationFileName(name);
>            String a = factory.getBasePath();                           
> //test code
>            String b = factory.getConfigurationFileName();     //test code
>            config = factory.getConfiguration();
>                  } catch (ConfigurationException eio) {
>            logger.fatal("PlanLogix - Error Reading Configuration file: 
> "+name+" Execution halted");
>            logger.fatal("PlanLogix - Error: "+eio.getCause()+" 
> Message: "+eio.getMessage());
>            throw eio;
>        }
>    }
> ================================================================
> The 'name' is c:\PLConfig.xml    The value from 
> factory.getConfigurationFileName()   is PLConfig
> The value from  actory.getBasePath() is   "."
> I've also tried this with the same code used in the example in the 
> Commons 'Setting up Configuration Factory'
>
> ConfigurationFactory factory = new ConfigurationFactory();
> URL configURL = new File("config.xml").toURL();                <- 
> config.xml was c:\PLConfig.xml
> factory.setConfigurationFileName(configURL.toString());
>
> This did nothing either.  When the getConfiguration method is called, 
> I get a CPU spike but when I try to extract values from the 
> configuration there is nothing there.
>
> I also tried using setBasePath(path) to no avail, just null pointer 
> exceptions.
> I've tried every variety of calsses and methods but nothing.
>
> Can anyone offer advice or a known working example?
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
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