On Wed, 19 Nov 2003, Carlos Rodriguez wrote:

> Hi:
>
> I am trying to load a properties file by using
> getResourceAsStream(), as follows:
>
> Properties log4Jprops = new Properties();
> String logFile = "/WEB-INF/properties/log4j.properties";
> InputStream in = this.getClassLoader().getResourceAsStream(debugFile);
>
> and unfortunately the InputStream is coming back null.
>
> I am running the servlet from a WAR, without expanding, on Tomcat
> 4.1.24. I have read in a lot of places that the thing to do is to
> package the props so that they are under "WEB-INF/classes". Is there
> no way to put them in another path above this?

In one application I've got my properties file directly in the WEB-INF
directory and I access it via:

  InputStream in = getServletContext().getResourceAsStream("WEB-INF/" + propsFile);

I see two differences between this and what you have above.  First,
you have a "/" before "WEB-INF" in your file path, and you use the
Class Loader's getResourceAsStream while I'm using the Servlet
Context's.  I'd investigate those two differences if I were you
(i.e. try the alternatives and see what happens).

Oh, just noticed another thing.  You set logFile, but you're passing
debugFile to your getResourceAsStream.  Maybe that's just a difference
you were experimenting with.  But I think the above two differences
still stand out as the significant ones.

Anyway, I see no reason you shouldn't be able to have a
WEB-INF/properties directory where you keep your properties files.

Milt Epstein
Research Programmer
Integration and Software Engineering (ISE)
Campus Information Technologies and Educational Services (CITES)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to