commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Grant Ingersoll" <>
Subject Re: [configuration] Properties files in jars
Date Wed, 17 Nov 2004 13:37:57 GMT
What should base be set to in this case?  Is it the JAR protocol
specification, as in jar:file:///

Thanks for the patch!


>>> 11/16/2004 9:57:55 PM >>>
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=""/>

The file 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
     if (base == null)
         url = new URL(name);
         URL baseURL = new URL(base);
         url = new URL(baseURL, name);

         // check if the file exists
         InputStream in = null;
             in = url.openStream();
             if (in != null)

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

Thanks God that was not a classloading issue :)

Emmanuel Bourg

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message