ResourceBundle Question

D

dennishancy

I have this code:

---------------------

ResourceBundle bundle = ResourceBundle.getBundle( "EUWConfig" );

_loggerFileTemp = bundle.getString("LoggerFile");

---------------------

Being new to most things about Java, I have some questions about this.

1) Is it assumed that "EUWConfig" is a properties file? Or do I need
to specify?

2) What folder does that file have to be in?

3) In my EUWConfig.properties file, I have a property called
LoggerFile. Is the syntax of the second line correct?

It seems to compile OK. The problem is when I run it, the web page
will not display. Can someone point me in the right direction?
Thanks.


Dennis Hancy
Eaton Corporation
Cleveland, OH
 
T

Thomas Fritsch

I have this code:

---------------------

ResourceBundle bundle = ResourceBundle.getBundle( "EUWConfig" );

_loggerFileTemp = bundle.getString("LoggerFile");

---------------------

Being new to most things about Java, I have some questions about this.

1) Is it assumed that "EUWConfig" is a properties file? Or do I need
to specify?
Yes, "EUWConfig.properties" is assumed to be a properties file.
(It may also be a file "EUWConfig.class" containing a subclass of
ResourceBundle.
But I tend to avoid this resource technique.)
2) What folder does that file have to be in?
If you load it with
bundle = ResourceBundle.getBundle("EUWConfig");
then the file "EUWConfig.properties" has to be in the same folder where
the class-files of the name-less package are.

More generally you can put it into any folder of your package hierarchy.
But then you have to specify a fully package-qualified name, for example
bundle = ResourceBundle.getBundle("your.package.EUWConfig");
which will load the file "your/package/EUWConfig.properties".
In other words: the file is loaded from the same folder where the
class-files of package "your.package" are.
3) In my EUWConfig.properties file, I have a property called
LoggerFile. Is the syntax of the second line correct?
Yes, supposed you have a line
LoggerFile=any string you like
in your properties file.
 
H

hiwa

I have this code:

---------------------

ResourceBundle bundle = ResourceBundle.getBundle( "EUWConfig" );

_loggerFileTemp = bundle.getString("LoggerFile");

---------------------

Being new to most things about Java, I have some questions about this.

1) Is it assumed that "EUWConfig" is a properties file?
Yes. It is a .properties file.

Or do I need
to specify?

2) What folder does that file have to be in?
Somewhere in the class path.
(For a typical Web app, /app/WEB-INF/classes directory is used.)
3) In my EUWConfig.properties file, I have a property called
LoggerFile. Is the syntax of the second line correct? Yes.

It seems to compile OK. The problem is when I run it, the web page
will not display. Can someone point me in the right direction?
Where have you stored the EUWConfig.properties file?
 
T

Thomas Weidenfeller

1) Is it assumed that "EUWConfig" is a properties file? Or do I need
to specify?

It has to follow the syntax rules for properties files, yes.
2) What folder does that file have to be in?

The complete lookup procedure is described in the API documentation.
3) In my EUWConfig.properties file, I have a property called
LoggerFile. Is the syntax of the second line correct?

Maybe. You didn't show us the contents of the file.
It seems to compile OK. The problem is when I run it, the web page
will not display.

What web page?
Can someone point me in the right direction?

See the API documentation and Sun's I18N tutorial.

/Thomas
 
D

dennishancy

My EUWConfig.properties file is in the root directory on server.

I have a jar file in root/WEB-INF/lib/


What changes need to be made to this line: bundle =
ResourceBundle.getBundle("EUWC­onfig"); ?


Thanks.


Dennis
 
I

Igor Kolomiyets

If your properties file is not part of the .jar file put it into
root/WEB-INF/classes
If it is packed with jar then it should be laced to the root of the ja
archive.

Best regards,
Igor.

(e-mail address removed) пишет:
 
T

Tor Iver Wilhelmsen

1) Is it assumed that "EUWConfig" is a properties file? Or do I need
to specify?

No, it will look for properties first (e.g.
"EUWConfig_en_US.properties" for that Locale) then for classes
implementing ResourceBundle. The first case is a special handling for
PropertyResourceBundle, the latter will usually be a subclass of
ListResourceBundle.
2) What folder does that file have to be in?

It has to be on the classpath. Without a leading package name it will
look in the default package (root of classpath).
3) In my EUWConfig.properties file, I have a property called
LoggerFile. Is the syntax of the second line correct?

Yes.
 
D

dennishancy

Ok, so how do I find out where the classpath is? How do I change it?

Thanks.


Dennis
 
D

dennishancy

From what we can tell, the code is bombing on the second line.

Just for kicks, we changed EUWConfig to EUWConfigX in the code,
commented out the second line, and the app runs fine.

We then uncomment line 2, change the name of the property file back to
what it should be, and the app blows up. It's as if the getBundle
method doesn't even check for a valid propery file. It stops on the
getString method. But I don't know why.

Can anyone shed some light on this?

As a reminder, here are the two lines of code:

---------------
ResourceBundle bundle = ResourceBundle.getBundle( "EUWConfig" );
_loggerFileTemp = bundle.getString("LoggerFile")­;
--------------


Thanks.


Dennis
 
H

hiwa

Just for kicks, we changed EUWConfig to EUWConfigX in the code,
commented out the second line, and the app runs fine.

We then uncomment line 2, change the name of the property file back to
what it should be, and the app blows up. It's as if the getBundle
method doesn't even check for a valid propery file. It stops on the
getString method. But I don't know why.

Can anyone shed some light on this?

As a reminder, here are the two lines of code:

---------------
ResourceBundle bundle =3D ResourceBundle.getBundle( "EUWConfig" );
_loggerFileTemp =3D bundle.getString("LoggerFile")=AD;
--------------


Thanks.


Dennis

We may need to see your whole deployment structures and each of relevant
files.
 

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,011
Latest member
AjaUqq1950

Latest Threads

Top