I have seen some answers concerning how to load a particular file within a jar through getResourceAsStream, and I can manage this. However I am facing something really specific an I could not find an answer about this on the forum.
Here is the configuration:
I have a jar file having a conf directory that contains 2 properties files messages_en_US.properties and messages_fr_FR.properties. The classical way to load such resources is to use
ResourceBundle.getBundle("messages", java.util.Locale.getDefault());
If the files were on disk, in a directory referenced by the program classpath, this works fine. But I don't know how I can manage combining use of ResourceBundle.getBundle and use of resources from within a jar. Indeed, as I cannot see any bridge through getResourceAsStream (or this would imply managing locale by myself to specify the entire resource file name, which is not very smart).
If it's in a conf directory inside the jar, then the package of the bundle you're trying to load is conf
, and you should use
ResourceBundle.getBundle("conf.messages", java.util.Locale.getDefault());
The javadoc says:
baseName - the base name of the resource bundle, a fully qualified class name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With