tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: (argh!) RE: Location of application-specific properties files
Date Wed, 07 Aug 2002 07:02:57 GMT

I did never intend, that you have to include the WEB-INF or classes part
into the path. The servlet spec says, that the folder "WEB-INF/classes"
will be mounted into the application classpath as well as every jar in
"WEB-INF/lib". So a properties file named placed in the
"WEB-INF/classes" folder (or in any of the mounted jars) will be found from
inside your application with the simple path "MyProp" or if you use
getResourceAsStream() with "". No folders, no magic, no
servlet dependency. It is the same process like finding a class - and a
class should never reside directly in the "WEB-INF" folder.


Jens Stutte

                    Jacob Kjome                                                          
                    <        To:     "Tomcat Users List"                  
                    m>                   <>       
                    07/08/2002           Subject:     Re: (argh!) RE: Location of        
                    05.49                application-specific properties files           
                    respond to                                                           
                    "Tomcat Users                                                        

Do you literally have the filename as

The only thing that knows about that is the ServletContext.  If you were to

use that method you'd be better off storing your config file in
"WEB-INF" and doing:


Since you want to avoid this so that your app is not servlet specific, you
can do the following....






Notice in all the cases where you are looking in the classpath/classloader,

you do not reference "WEB-INF" or the "classes" directory within
WEB-INF.  The classloader doesn't know about those.  The ServletContext, on

the other hand, knows about everything inside the root of the current

That should solve things.


At 09:22 PM 8/6/2002 -0400, you wrote:
>Thanks for the reply.  I understand what you're saying, and I wish it was
>working for me, but it doesn't.  The ONLY way I've been able to get this
>work is by using the servlet context method as mentioned in a previous
>but that's NOT the way I want this to ultimately work.
>I want to make it as generic as possible without having to rely on passing
>in a servlet context to my class.  For example, what if I need access to
>that file in an application that's not using a servlet?
>If I have the filename as "/WEB-INF/classes/", I have
>tried this in one of four different ways so far:
>1. load(new FileInputStream(filename));
>3. load(this.getClassLoader().getResourceAsStream(filename));
>4. load(getServletContext().getResourceAsStream(filename));
>All of them fail for not finding the file except #4, but that's not the
>optimal solution as mentioned previously.
>As an aside, I pulled the "java.class.path" from the System properties to
>see where it's pointing, and all it has in it is
>"<CATALINA_HOME>\bin\bootstrap.jar" with no other paths included.
>-----Original Message-----
>From: []
>Sent: Tuesday, August 06, 2002 9:56 AM
>To: Tomcat Users List
>Subject: Re: Location of application-specific properties files
>You must load your properties through some Classloader that is able to
>locate your properties file.  For example you can use the class
>PropertyResourceBundle for a real properties file or if you want to access
>some own file format, just call the Thread.getCurrentThread
>().getContextClassLoader().getResourceAsStream(...) function. Then the
>WEB-INF/classes folder or some of your application specific .jar files in
>WEB-INF/lib (if any) is the right place for it (and as far as i know, it
>the only standard way, which assures you to find a specific file on every
>standard J2EE server).
>To unsubscribe, e-mail:   <>
>For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message