I have a servlet running under Tomcat. I'd like to load a
ResourceBundle that resides outside the servlet's context (directory).
I know how to get it from WEB-INF/classes:
ResourceBundle.getBundle("Basename", locale);
and I know how to get it out of some deployed package directory,
relative to WEB-INF/classes:
ResourceBundle.getBundle("com.company.package.Basename", locale);
But I was hoping I could load it from a directory that is not in the
webapp context -- for example, /opt/local/config/Basename.properties.
I tried the following two permutations, but both throw
MissingResourceException:
ResourceBundle.getBundle("/opt/local/config/Basename", locale);
ResourceBundle.getBundle(".opt.local.config.Basename", locale);
I suspect that I need to somehow get /opt/local/config on my classpath,
but not sure if that is it or not...
Anyone seen anything like this before?
thanks
scott
Roedy Green - 04 Oct 2007 02:54 GMT
> ResourceBundle.getBundle("/opt/local/config/Basename", locale);
> ResourceBundle.getBundle(".opt.local.config.Basename", locale);
Locale currentLocale = Locale.getDefault();
System.out.println( currentLocale ); // e.g. en_CA
// select the ResourceBundle closest fit to this locale
// note, you don't specifiy the .properties or _en_CA
// A corresponding resource might be called
MyResources_en_CA.properties
// Unlike ordinary resources handling, getBundle will
// not prepend the package name on the resource automatically.
ResourceBundle myResources =
ResourceBundle.getBundle( "MyResources", currentLocale );
Look in your jar. What is the fully qualified resourceBundle name . It
depends on how you did your build what it is. It might not even be
there.
see http://mindprod.com/products.html#JARLOOK

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Arne Vajhøj - 04 Oct 2007 03:24 GMT
> I have a servlet running under Tomcat. I'd like to load a
> ResourceBundle that resides outside the servlet's context (directory).
[quoted text clipped - 5 lines]
> and I know how to get it out of some deployed package directory,
> relative to WEB-INF/classes:
Two possible roads:
1) call getBundle with an URLClassLoader instance that reads
from the directory you want
2) use PropertyRessourceBundle constructor instead of
ResourceBundle.getBundle
Arne