Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

ResourceBundle.getBundle from Tomcat, to "external" directory

Thread view: 
Scott Harper - 04 Oct 2007 02:36 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.