ResourceBundle.getBundle from Tomcat, to "external" directory

S

Scott Harper

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
 
R

Roedy Green

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
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Scott said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top