Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat Server creating Directories in tmp

Everytime my embedded virtual tomcat server is ran (spring boot) it creates a directory structure in /tmp/ that is named tomcat.##########################.8080 (I am guessing 8080 is for port or something but the 8080 is consistent). This structure does not take up much space alone but after running the tomcat server often over time this can fill up. Can I prevent this from happening as a configurable option?

An example of the path created can look something like: /tmp/tomcat.1185139485157901.8080/work/Tomcat/localhost/_/ SESSIONS.ser WEB-INF/ etc. etc. etc.

like image 617
user3684399 Avatar asked Jan 09 '15 16:01

user3684399


People also ask

Can we delete Tomcat temp folder?

Yes, the tomcat/temp directory is safe to delete when the server is stopped.

What is Tomcat docBase?

The docBase attribute is a path to the WAR file or exploded deployment directory. It is relative to the webapps directory, although an absolute path can be used. The path attribute is the one we are most interested in, as it defines the context path of the application.

What is work folder in Tomcat?

The work directory, as its name suggests, is where Tomcat writes any files that it needs during run time, such as the generated servlet code for JSPs, the class files for the same after they are compiled, the serialized sessions during restarts or shutdowns (SESSIONS. ser).


1 Answers

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.

like image 142
Joey Avatar answered Oct 04 '22 14:10

Joey