Tomcat Server creating Directories in tmp
Unfortunately, both embedded and non-embedded Tomcat needs to have a directory to store temporary files. This is not configurable, however, you can specify the directory in which Tomcat stores these temporary files using setBaseDir
.
This should be the first method called public void setBaseDir(String basedir)
and if it is not specified in your code it will look for it in
system properties - catalina.base, catalina.home - $HOME/tomcat.$PORT
By knowing the location I recommend writing a simple scheduled script that checks every so often and removes the files under that directory.
Clarifications on Tomcat's temp and work directories
work
stores compiled JSPs and other assets.
=> You only need to "clean" the webapp directories under it on the rare occasions when an update to a WebApp is not picked up.temp
is used to store files created using the Java File API for creating temporary files.
=> You can "clean" it every time you restart Tomcat. If it is getting too full then one of your WebApps may have some form of leak where its not releasing temp files when its done with them (although it could just be under higher load too).
Spring Boot with embedded tomcat creates empty directories in temp folder
You can control the location of the directory using server.tomcat.basedir
. As you have observed, it defaults to a temporary directory, but you can configure a different location if needed.
Allocation of temp directory inside tomcat installation base results in error due to read only property
It turns out there are a lot of questions and answers on stackoverflow about changing the value of java.io.tmpdir.
Initially I set a windows system variable CATALINA_TMPDIR to c:/new/temp/dir, but as this is a system wide setting I ultimately decided to not use that method.
The simplest method and most direct was to use CrazyCoders suggestion.
Under Run -> Edit Configurations.
In the Server tab of the Tomcat Server, in the VM options box enter -Djava.io.tmpdir=c:/new/temp/dir
Best practice to save temp files on tomcat?
Use the property java.io.tmpdir
to get the tomcat
temp folder and save your files there. That will be a good place to temporarily keep them in. So you can define it as follows:
public static final String TMP_DIR = System.getProperty("java.io.tmpdir")
The temporary upload location [/tmp/tomcat.4296537502689403143.5000/work/Tomcat/localhost/ROOT] is not valid
- The http POST methods will use these temp locations to store the post data.
- Some OSs like centOS will delete the temp dir frequently. So, even you set that location's permission, after some time that dir will be removed by the OS. And after you reboot, the temp dir will be different.
You can set the multipart location in application.yml:
spring:
http:
multipart:
location: /data/upload_tmp
Update
As per comment by Vivek Sethi above property didn't work for me but the below one.
spring.servlet.multipart.location=/data/upload_tmp
How is the Tomcat temp directory location defined?
When you start Tomcat with catalina.sh (or catalina.bat), the temp directory is set with the CATALINA_TMPDIR variable:
if [ -z "$CATALINA_TMPDIR" ] ; then
# Define the java.io.tmpdir to use for Catalina
CATALINA_TMPDIR="$CATALINA_BASE"/temp
fi
Also you can pass below as VM argument while starting Tomcat in Eclipse to use it as temp directory.
-Djava.io.tmpdir="C:\Program Files\liferay-portal-5.2.3-tomcat-6.0\tomcat-6.0.18\temp"
Related Topics
Pyinstaller on 32-Bit Linux - Importerror: The 'six' Package Is Required
Thread Quantum: How to Compute It
Using Mutexes/Semaphores with Processes
How Does Ltrace (Library Tracing Tool) Work
How to Use Sed to Delete Leading Digits
Unix Unzip: How to Batch Unzip Zip Files in a Folder and Save in Subfolders
Golang Os/Exec, Realtime Memory Usage
Linux Patch Ignoring Line Numbers
Overwriting Yocto Classes Through Meta-Layer
Opening Sockets to The Xserver Directly
Convert Charset from a Entire Project to Utf-8
Qxcbconnection: Could Not Connect to Display Aborted, When Installing Qt on Linux
Bash Redirect to /Dev/Stdout: Not a Directory
Linux Umask for Sudo and Apache
How to Deploy Files for a Remote Debug Launch in Eclipse Cdt