commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Bourg <sma...@lfjr.net>
Subject Re: [configuration] Properties files in jars
Date Wed, 17 Nov 2004 02:57:55 GMT
Ok I think I understand why it's not working. I wrote a test case, I'll 
commit it once it's polished. The problem is the following:

The configuration descriptor (config.xml) lies in a JAR, let say 
foo.jar. It declares a properties file with

<properties fileName="config.properties"/>

The file config.properties can be in another JAR, on the classpath or 
anywhere else it doesn't matter.

When the ConfigurationFactory is built, the basepath points to foo.jar, 
that means the PropertiesConfiguration is initialized with the same 
basepath, and it will attempt to load the file from foo.jar instead of 
looking for the file on the classpath.

The cause of this issue is a bug in ConfigurationUtils.locate(), we 
attempt to locate the file by building an URL, we just check if the URL 
is valid (here a JAR URL), but we don't check if the file exists...  So 
in this case we never search the file on the classpath.

Here is a patch fixing this bug, I'll commit it tomorrow:

// attempt to create an URL directly
try
{
     if (base == null)
     {
         url = new URL(name);
     }
     else
     {
         URL baseURL = new URL(base);
         url = new URL(baseURL, name);

         // check if the file exists
         InputStream in = null;
         try
         {
             in = url.openStream();
         }
         finally
         {
             if (in != null)
             {
                 in.close();
             }
         }
     }

     log.debug("Configuration loaded from the URL " + url);
}
catch (IOException e)
{
     url = null;
}


Thanks God that was not a classloading issue :)

Emmanuel Bourg


Mime
View raw message