You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Craig R. McClanahan" <Cr...@eng.sun.com> on 2001/03/01 06:49:23 UTC

Re: Has any one used struts and log4j successfully?

Mark Balster wrote:

>             FileInputStream inFile = new
> FileInputStream(getServletContext().getRealPath(messages.getMessage("Log.Pro
> pertiesFile")) );

You should also be aware that this will only work if your servlet container
unpacks your web application into an open directory structure.  If it runs
directly out of the WAR file (or out of blob objects in a database, for
example), the getRealPath() call will return null.

In such a case, you might wish to use the temporary working directory provided
to you by the servlet container as a context attribute:

    File workDir = (File)
      getServletContext().getAttribute("javax.servlet.context.tempdir");
    File logFile =
      new File(workDir, messages.getMessage("Log.Properties.File"));
    String logPathname = logFile.getAbsolutePath();

Of course, there are no guarantees that the temporary work directory will
survive the shutdown of your servlet container -- check the container docs for
specifics.

Craig