users
[Top] [All Lists]

RE: [cinjug-users] properties file in WAR

To: "Maoshi GU" <maoshi@xxxxxxxxx>, "James Carman" <james@xxxxxxxxxxxxxxxxxxxx>
Subject: RE: [cinjug-users] properties file in WAR
From: "Herbers, Joe" <joe.herbers@xxxxxxx>
Date: Thu, 26 Jun 2003 08:57:36 -0400
Cc: <users@xxxxxxxxxx>
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Thread-index: AcM734+AyfwQCqfPEdeOuQCgyZkotgAAbepw
Thread-topic: [cinjug-users] properties file in WAR
Ok, I'm trying putting it in the same dir in the WAR as the JSP (which is a 
subdir under the root)...failed.  So to summarize, with the code we're using 
(calling static ResourceBundle.getBundle) it only seems to be able to access 
resources located in the root of the WAR.  This is contrary the belief that it 
should load from anywhere on the WAR's classpath, which seems to be the default 
way to access "resources" if you read docs like this on Tomcat's site.  Little 
confusing, but hey, I'm learning something (I think :-)

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html


-----Original Message-----
From: Maoshi GU [mailto:maoshi@xxxxxxxxx]
Sent: Thursday, June 26, 2003 8:36 AM
To: James Carman; Herbers, Joe
Cc: users@xxxxxxxxxx
Subject: Re: [cinjug-users] properties file in WAR

ResourceBundle can use an absolute path, e.g, /usr/local, where you can put 
your property files. If no defined, it uses where your class file lives. In 
your case, I believe it gets the file from your jsp file directory, which may 
be the doc root.


-----Original Message-----
From: James Carman [mailto:james@xxxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, June 25, 2003 4:42 PM
To: Herbers, Joe
Cc: users@xxxxxxxxxx
Subject: Re: [cinjug-users] properties file in WAR

Ok, first of all you should NOT do this in JSP code.  If you really want
this sort of support, either use Struts or JSTL.  Anyway, it looks like it
SHOULD be placed in the WEB-INF/classes directory based upon this code.  The
ResourceBundle class will use the ClassLoader.getResource() approach.  I'd
have to see your war file setup to figure out why it's not working.


-----Original Message-----
From: James Carman [mailto:james@xxxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, June 25, 2003 4:20 PM
To: Herbers, Joe; Timothy Dennison; CinJUG (E-mail)
Subject: Re: [cinjug-users] properties file in WAR

Well, it depends on how you're loading the file.  Are you using the
ServletContext.getResource() or ClassLoader.getResource() method?  If you
use the ServletContext.getResource() method, the searching is done rooted at
the root of your webapp.  But, if you use the classloader, it will be rooted
at WEB-INF/classes (or the root of one of your jars in WEB-INF/lib).


----- Original Message ----- 
From: "Herbers, Joe" <joe.herbers@xxxxxxx>
To: "James Carman" <james@xxxxxxxxxxxxxxxxxxxx>; "Timothy Dennison"
<denti07@xxxxxxxxx>; "CinJUG (E-mail)" <users@xxxxxxxxxx>
Sent: Wednesday, June 25, 2003 3:23 PM
Subject: RE: [cinjug-users] properties file in WAR

Sorry I'm slow following up to these helpful responses to my question.  I
just got around to testing this out.  It only worked when I put the file
(messages.properties) in the WAR's root dir.  It couldn't locate it if I put
it in WEB-INF/classes or WEB-INF/lib.  This was using an exploded WAR in
JBoss' deploy dir.

So I can just put it in the root when I make a WAR file.  But I'm curious
how this is supposed to work.  James mentioned reading the docs - any
recommendations for docs on how WAR files can be put together?

Thanks, Joe


-----Original Message-----
From: James Carman [mailto:james@xxxxxxxxxxxxxxxxxxxx]
Sent: Saturday, June 14, 2003 12:52 PM
To: Timothy Dennison; CinJUG (E-mail)
Subject: Re: [cinjug-users] properties file in WAR

You can put it in the WEB-INF/classes directory as Tim has suggested, or it
can be in the top-level of any of the jars in the WEB-INF/lib directory and
it will also be found.  If you're using Tomcat.  Try doing a
System.out.println() on one of your classes' ClassLoader object.  It will
give you a rundown of all of the places where it will look for resources.
It's VERY helpful when trying to figure out where things are loaded from and
in what order.  The docs help too. :-)  I would suggest using the
WEB-INF/classes directory, though.  That's the absolute first place it will
look.


----- Original Message ----- 
From: "Timothy Dennison" <denti07@xxxxxxxxx>
To: "CinJUG (E-mail)" <users@xxxxxxxxxx>
Sent: Saturday, June 14, 2003 6:15 AM
Subject: Re: [cinjug-users] properties file in WAR

> You should be able to put the file in WEB-INF/classes
> as this location will always be on the classpath.
> tim

> --- "Herbers, Joe" <joe.herbers@xxxxxxx> wrote:
> > I'm trying to create a WAR file to deploy an app.
> > One class references a resource file called
> > message.properties via the following code.  Where in
> > the WAR should/can I put the properties file?  In
> > the root?  I think it needs to be in the classpath,
> > so I do I need to put a CLASSPATH statement in
> > Manifest.mf or can I put it somewhere that will
> > automatically be in the classpath?  Thanks.
> >
> >             bundle =
> > ResourceBundle.getBundle("Message",userLocale);
> >

<Prev in Thread] Current Thread [Next in Thread>