Loading order of property files?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Loading order of property files?

Michael Bishop
I've run into the problem here at work where a project's source contains a property file.  However, that same project is dependent on some JAR files, one of which contains a property file of the same name.  The problem is that the JAR's property file takes precedence over the one in the source.  The workaround was to delete the one inside the JAR, but is there a way to give priority to one over the other?  I'd think the default behavior would be the order in which the classes are loaded (last one takes precedence), and I'd imagine JAR files and supporting libraries would be loaded before source.  Can anyone provide insight?
 
Michael Bishop
Reply | Threaded
Open this post in threaded view
|

Re: Loading order of property files?

Tom Ball
Michael Bishop wrote:

> I've run into the problem here at work where a project's source contains
> a property file.  However, that same project is dependent on some JAR
> files, one of which contains a property file of the same name.  The
> problem is that the JAR's property file takes precedence over the one in
> the source.  The workaround was to delete the one inside the JAR, but is
> there a way to give priority to one over the other?  I'd think the
> default behavior would be the order in which the classes are loaded
> (last one takes precedence), and I'd imagine JAR files and supporting
> libraries would be loaded before source.  Can anyone provide insight?
>  
> Michael Bishop

java.util.ResourceBundle.getBundle() uses
ClassLoader.getResourceAsStream(path + ".properties") to find a
properties file, and so you are at the mercy of whatever search order
your ClassLoader uses.  You can use "new PropertyResourceBundle(stream)"
to create a bundle from a specific file.  A better solution is to use
separate packages in the two jar files, instead of sharing a common one
across them.  That way the existing core implementation should work.

Tom
Reply | Threaded
Open this post in threaded view
|

Re: Loading order of property files?

Tom Ball
Tom Ball wrote:

> Michael Bishop wrote:
>
>> I've run into the problem here at work where a project's source
>> contains a property file.  However, that same project is dependent on
>> some JAR files, one of which contains a property file of the same
>> name.  The problem is that the JAR's property file takes precedence
>> over the one in the source.  The workaround was to delete the one
>> inside the JAR, but is there a way to give priority to one over the
>> other?  I'd think the default behavior would be the order in which the
>> classes are loaded (last one takes precedence), and I'd imagine JAR
>> files and supporting libraries would be loaded before source.  Can
>> anyone provide insight?
>>  
>> Michael Bishop
>
>
> java.util.ResourceBundle.getBundle() uses
> ClassLoader.getResourceAsStream(path + ".properties") to find a
> properties file, and so you are at the mercy of whatever search order
> your ClassLoader uses.  You can use "new PropertyResourceBundle(stream)"
> to create a bundle from a specific file.  A better solution is to use
> separate packages in the two jar files, instead of sharing a common one
> across them.  That way the existing core implementation should work.

One more option: rename "Bundle.properties" to something else +
".properties", as the name itself is just a NetBeans convention.

Tom