tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garret Wilson <>
Subject Re: no temp directory creation wanted when embedding Tomcat
Date Tue, 23 Apr 2019 20:46:00 GMT
On 4/22/2019 7:58 AM, Mark Thomas wrote:
> On 21/04/2019 15:53, Garret Wilson wrote:
>> …
>> But now I realize Tomcat is creating this directory structur inside the
>> "base dir" I specified:
>> tomcat.8080/work/Tomcat/localhost/ROOT
>> I don't need this directory. I don't want this directory created. How do
>> I tell Tomcat not to create no danged directories?
> The Servlet specification requires (see section 4.8.1 of the Servlet 4.0
> spec) that Tomcat provides a private temporary directory for each
> servlet context (web application).

I have have several reactions.

1. The first is, OK, so the servlet spec requires that the servlet 
container expose a temporary directory. Tomcat can't provide a temporary 
directory to the consumer unless it has a temporary directory, so it's 
reasonable that it creates one.

2. But so far nothing has been stored in this directory, so it's 
completely unused. I see also in the `Tomcat` class the comment, "lazy 
init for the temp dir - only when a JSP is compiled or get temp dir is 
called we need to create it. This will avoid the need for the baseDir". 
It sounds like you're lazily creating the JSP temporary directory, so 
why can't we do the same for the context temporary directory, which may 
never be used (and frankly probably won't be used in many applications)? 
But OK, that's a quibble; my other thoughts are more pressing.

3. Since the temporary working directory is on a per-context basis, and 
I've only set the "basedir" for the entire `Tomcat` instance, Tomcat 
must be determining a default temporary directory for the context. 
Surely I'm allowed to explicitly specify a temporary directory on a 
per-context basis, but I sure can't find it. The `StandardContext` seems 
to equate the "temporary directory" with the "work directory". Are they 
really the same? If so, I suppose I can just call 

> The best you can do is specify an absolute path that already exists for
> the Context's work directory. It doesn't need to be writeable. If you
> are using it for multiple web applications you probably don't want it to
> be writeable.

Ah, OK—I had read that response earlier, but didn't understand exactly 
what it meant until I investigated and wrote #2 above. So I guess I was 
right: I need to call`((StandardContext)context).setWorkDir(String)`.

4. But all this "temporary directory requirement" business is for 
servlet containers. I started out just wanted to embed Tomcat to serve 
static files; I don't (yet? ever?) need a servlet container for this 
particular application. So how can I use Tomcat to serve static files 
without bringing in the requirements of a servlet container?

Maybe the answer is that Tomcat serves files by using a 
static-file-serving servlet, which in turn requires me to use Tomcat as 
a servlet container even for serving static files, which in turn 
requires me to have a temporary directory I don't want or need.

I suppose that's just the way it is. This is not so much a complaint as 
a desire to confirm I understand correctly how things stands. (OK, it's 
a teeny-tiny complaint, too.)


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

View raw message