16

My Tomcat instance is sitting on a drive with little remaining space. The application I'm running does move file uploads off the server and into a NAS. During the upload, however, Tomcat keeps this file locally, presumably in the /temp directory.

My server has a second data drive with plenty of space where I'd like to relocate this temp directory to. How can I configure Tomcat so that it uses a temp directory on this other drive, ie. how can I relocate this directory?

Edit: I'm running Windows server 2k3. I tried setting the CATALINA_TMPDIR env var, but Tomcat appeared to ignore it.

Solution: I'm using the "Monitor Tomcat" application which passes

-Djava.io.tmpdir=C:\some\default\directory

to the JVM. This was overriding the environmental variable I was setting. You can find it under Java > Java Options

Changing this has fixed my problem.

rcampbell
  • 1,035
  • 4
  • 14
  • 24

3 Answers3

25

The java.io.tmpdir in Tomcat is set to $CATALINA_BASE/temp. You can change it by setting the $CATALINA_TMPDIR environment variable before running startup.sh for Tomcat.

From catalina.sh:

#   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
#                   the JVM should use (java.io.tmpdir).  Defaults to
#                   $CATALINA_BASE/temp.
OtherDevOpsGene
  • 2,532
  • 20
  • 16
  • 1
    This appears to only work for *nix systems, because when I tried setting CATALINA_TMPDIR env var in Windows 2k3 and booted up Tomcat, it continued using the default temp folder. – rcampbell May 30 '09 at 10:40
  • If you set a system environment variable in Windows, you may need to reboot before it takes effect. – OtherDevOpsGene Jun 18 '09 at 13:32
  • On Ubuntu you can set the temp directory in `/etc/default/tomcat7` – beldaz May 23 '16 at 07:54
3

On windows if you are running Tomcat as a service you likely have a key similar to

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\myApplication\Parameters\Java

Set the string value options (double click to open) at the end of existing as:

-Djava.io.tmpdir=c:\{yourDir}

This worked for me.

notpeter
  • 3,515
  • 2
  • 26
  • 44
Ken Smith
  • 31
  • 1
2

If you're on UNIX/Linux you can just symlink your temp directory on a first drive to the corresponding directory on a second drive. Maybe not a most elegant solution but it worked for me sometime.

Slava I.
  • 281
  • 1
  • 4