You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Charles Griswold <cg...@logixpartners.com> on 2005/03/02 16:59:59 UTC
Commons Configuration Problem
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
Re: Commons Configuration Problem
Posted by Emmanuel Bourg <eb...@apache.org>.
The configuration descriptor is not mandatory, if you have a single
configuration you can use directly:
Configuration conf = new XMLConfiguration("FooBar.xml");
Emmanuel Bourg
Charles Griswold wrote:
> Thank you for your reply. I have since solved the problem. Commons
> Configuration wants to have an xml configuration file with the
> <configuration> tag. Within this file I point to the real
> configuration via:
>
> <configuration> <xml
> fileName="C:/Root/PlanLogix/Website/Logos/FooBar.xml"/>
> </configuration>
> The FooBar.xml contains all my parameters.
> Seems wierd to me that this can't be all one file.
>
> ---------------------------------------------------------------------
> 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
Re: Commons Configuration Problem
Posted by Charles Griswold <cg...@logixpartners.com>.
Thank you for your reply. I have since solved the problem. Commons
Configuration wants to have an xml configuration file with the
<configuration> tag. Within this file I point to the real
configuration via:
<configuration>
<xml fileName="C:/Root/PlanLogix/Website/Logos/FooBar.xml"/>
</configuration>
The FooBar.xml contains all my parameters.
Seems wierd to me that this can't be all one file.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Commons Configuration Problem
Posted by Oliver Heger <ol...@t-online.de>.
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