Resource bundle class lookup

M

michapringle

Hi,

Sorry if this is a duplicate post...

I wrote a class that duplicated some functionality from the
ResourceBundle class, namely the ResourceBundle.getBundle method,
which loads a .properties file, from a directory provided by the JVM.

Example:
ResourceBundle configurationFileProperties =
ResourceBundle.getBundle( Point.class.getName() );

The problem I run into is when I run my own code under tomcat. I think
the base directory provided by the JVM is .../webapp/WEB-INF/classes;
this is where the ResourceBundle knows to look, even if it isn't the
default directory specified by the OS. To make a long story short, I
think I can solve my problem if I can somehow get the base directory
specified by the JVM. System.getProperties doesn't seem to contain
this particular directory. I did look through the ResourceBundle
source, but no luck.

Can someone help me out with this? Thanks.

Please ask if there are any questions, or clarifications needed.

Cheers,
Micha
 
L

Lew

Hi,

Sorry if this is a duplicate post...

I wrote a class that duplicated some functionality from the
ResourceBundle class, namely the ResourceBundle.getBundle method,
which loads a .properties file, from a directory provided by the JVM.

Example:
ResourceBundle configurationFileProperties =
ResourceBundle.getBundle( Point.class.getName() );

The problem I run into is when I run my own code under tomcat. I think
the base directory provided by the JVM is .../webapp/WEB-INF/classes;
this is where the ResourceBundle knows to look, even if it isn't the
default directory specified by the OS. To make a long story short, I
think I can solve my problem if I can somehow get the base directory
specified by the JVM. System.getProperties doesn't seem to contain
this particular directory. I did look through the ResourceBundle
source, but no luck.

Can someone help me out with this? Thanks.

I'm not clear whether you want to look in WEB-INF/classes or somewhere else,
and I'm also slightly confused by your references to ".../" and "webapp/",
which latter made me think briefly of Tomcat's "webapps" directory until I
figured that's probably (?) not what you meant.

If you actually want to locate your bundle in your app's "WEB-INF/classes/"
subdirectory, ClassLoader.getResource() or getResourceAsStream() may be what
you want. You also can root yourself in the context root by using the
same-named methods of javax.servlet.ServletContext.
 
M

michapringle

I'm not clear whether you want to look in WEB-INF/classes or somewhere else,
and I'm also slightly confused by your references to ".../" and "webapp/",
which latter made me think briefly of Tomcat's "webapps" directory until I
figured that's probably (?) not what you meant.

If you actually want to locate your bundle in your app's "WEB-INF/classes/"
subdirectory, ClassLoader.getResource() or getResourceAsStream() may be what
you want. You also can root yourself in the context root by using the
same-named methods of javax.servlet.ServletContext.

Hi Lew,

On re-inspection of the ClassLoader javadoc, I think is what I want.

Cheers,
Micha
 
M

michapringle

I'm not clear whether you want to look in WEB-INF/classes or somewhere else,
and I'm also slightly confused by your references to ".../" and "webapp/",
which latter made me think briefly of Tomcat's "webapps" directory until I
figured that's probably (?) not what you meant.

If you actually want to locate your bundle in your app's "WEB-INF/classes/"
subdirectory, ClassLoader.getResource() or getResourceAsStream() may be what
you want. You also can root yourself in the context root by using the
same-named methods of javax.servlet.ServletContext.

Oh, forgot to say thanks :)
 

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,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top