In my application, several libraries are assembled.
Whenever those libraries comes with resources having a same name, getResourceAsStream("myfile")
seems to return a stream to whatever file come first.
This is true for any file, including Resource bundles.
In the following example, a library with a MyMibrary class has a file called "config.properties". And does
InputStream is = MyLibrary.class.getResourceAsStream("/config.properties")
When called in a standalone context, the right config file is used.
But when loaded as a dependency from an application having its own "config.properties", the same statement returns the config file of the application instead of the one of the library.
The same applies also for ResourceBundles (which is using getResourceAsStream
too) :
If both the library and the application are using Resource bundles named the same way, when called from the application, the library will be using the application resource bundle instead of its own.
My question is how to instruct getResourceAsStream
(especially in the context of Resource bundle loading) to use the right resource ?
EDIT: this question differs partially from How to read several resource files with the same name from different in the way the latter question deals only with resources while my question deals also with ResourceBundles.