You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Shapira, Yoav" <Yo...@mpi.com> on 2002/08/08 18:07:20 UTC

RE: Getting the root directory of my ear file from a servlet.

Hi,

The servlet spec does not guarantee you will get a real path at all when
deploying from a war.  

You should never rely on getRealPath() in that case.  See the JavaDoc
for getRealPath() for a more 

complete explanation.  There have also been several discussions on this
matter on the tomcat-user mailing

list recently.

 

Instead, you should use getResource() or getResourceAsStream() in your
servlet.  

Yoav Shapira
Millennium ChemInformatics

-----Original Message-----
From: Alan Yost [mailto:Alan.Yost@yambay.com] 
Sent: Thursday, August 08, 2002 12:12 PM
To: Log4J Users List
Subject: Getting the root directory of my ear file from a servlet.

 

Hi all,

 

I'm trying to use the init() method of a class that extends HttpServlet
to read in a properties file when a servlet is first deployed.  I have
looked at the example on pg 13 of Ceki Gulcu's "Short introduction to
log4j" related to configuring log4j during initialisation.  The problem
I seem to be having is that when I specify the following code I don't
get the expected real path - but one that JBoss "mirrors" in the
background.

 

e.g

 

String prefix  =  config.getServletContext().getRealPath("/log4j.lcf");

 

Rather than return the get JBoss\..\deploy\MyDeployFile.ear\mypath I get
something like:

 

C:\Documents and Settings\alany\Local
Settings\Temp\Jetty__8080___yambay\webapp\meta-inf\log4j.lcf

 

Ideally what I would like to be able to do is to have a configuration
file in the root of "MyDeployFile.ear" and reference this but I am not
sure how to get this address.

 

Any ideas would be appreciated.

 

 

Regards

 

 

Alan.