Sean Nguyen
Sean Nguyen

Reputation: 13128

How to specify location of tomcat temporary folder?

When I start embedded tomcat, it creates a folder name "tomcat." + myportnumber for example: tomcat.8080. How can I specify the location of this temp folder. I am using maven, so I want this folder to be in the target folder so it will get clean with mvn clean command.

I am using embedded tomcat version 7.0.26

Upvotes: 8

Views: 3800

Answers (1)

acheron55
acheron55

Reputation: 5619

Use public void setBaseDir(String basedir) method.

"Tomcat needs a directory for temp files. This should be the first method called. By default, if this method is not called, we use: - system properties - catalina.base, catalina.home - $HOME/tomcat.$PORT ..."

import org.apache.catalina.startup.Tomcat;

Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("/mytmpfolder");
tomcat.addWebapp("/mywebapp", "/path/to/mywebapp");
tomcat.start();
tomcat.getServer().await(); 

Upvotes: 10

Related Questions