ResourceBundle.getBundle from Tomcat, to "external" directory  
Author Message
sharper3





PostPosted: 2007-10-4 9:36:00 Top

java-programmer, ResourceBundle.getBundle from Tomcat, to "external" directory 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





PostPosted: 2007-10-4 9:54:00 Top

java-programmer >> ResourceBundle.getBundle from Tomcat, to "external" directory On Thu, 04 Oct 2007 01:36:16 GMT, email***@***.com
(Scott Harper) wrote, quoted or indirectly quoted someone who said :

>
> 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
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Arne Vajh鴍





PostPosted: 2007-10-4 10:25:00 Top

java-programmer >> ResourceBundle.getBundle from Tomcat, to "external" directory Scott Harper wrote:
> 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:

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