The problem is that the file you pass to ConfigurationFactory is not of the expected format.

ConfigurationFactory reads XML files that refer to other configuration files. In these other files definitions for properties can be placed. What you try to do is parsing a file that defines a property with ConfigurationFactory.

You have two possibilities: Either load your configuration file directly with XMLConfiguration instead of ConfigurationFactory. Or create an additional configuration definition file that links to your configurtion file and let this file be read by ConfigurationFactory. Please refer to the HowTos on the Configuration website. They contain examples for both of these solutions.

Oliver

zhenyu Lu wrote:

hi, I am newbie for common configuration. I use common-configuration1.0rc and 
jdk1.4.2. My configuration file is like this:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<configuration>
 <host> localhost </host>
</configuration>



My program is :

public class ServerApp {

 /** Creates a new instance of MainApp */
 public ServerApp() {

 }

 /**
  * @param args the command line arguments
  */
 public static void main(String[] args) {
   try {
     Properties props = new Properties();

     ConfigurationFactory factory = new ConfigurationFactory();
     factory.setConfigurationFileName("Config.xml");
     Configuration config = factory.getConfiguration();
     /** These properties pertain to setting up a TCP link */
     String host = config.getString("host");
     System.out.println(host);
   }
   catch (Exception e) {
     e.printStackTrace();
   }
 }
}

I got a exception:

java.util.NoSuchElementException: 'host' doesn't map to an existing object
at 
org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:890)


Did I do someting wrong? I tried :

String host = config.getString("Configuration.host");

String host = config.getString("Configuration[0].host");

neither works.

Any idea? Thanks.








---------------------------------
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to