Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where/how to store persistent data with tomcat?

Tags:

java

tomcat

Where should I store persistent files in a Tomcat web app ?

  • javax.servlet.context.tempdir is not feasible, it's erased when the app is redeployed/removed
  • Don't want to use an absolute path in e.g. servlet init parameters
  • Storing the files in a database is not an option
like image 701
nos Avatar asked Nov 24 '09 20:11

nos


People also ask

Where does Tomcat store data?

By default, these files are located at TOMCAT-HOME/conf/server. xml and TOMCAT-HOME/conf/web. xml, respectively. Don't do the same configuration work twice.

What is session persistence in Tomcat?

Persistence Across Restarts Whenever Apache Tomcat is shut down normally and restarted, or when an application reload is triggered, the standard Manager implementation will attempt to serialize all currently active sessions to a disk file located via the pathname attribute.

What are the containers of Tomcat?

A Container is an object that can execute requests received from a client, and return responses based on those requests. A Container may optionally support a pipeline of Valves that process the request in an order configured at runtime, by implementing the Pipeline interface as well.


1 Answers

Our team does this a lot. A general rule we follow is outside the web app and outside Tomcat.

Our sysadmin set up a directory on our server that the tomcat user has rw permissions to (e.g. /var/tomcat/persist). We have a built a directory structure under this that tomcat uses to store files, read app-specific init files, etc.

If you don't want to use an absolute path in your init-params for your servlet, consider setting a system property when tomcat is started up. The good thing about that is every application running under tomcat will have access to it. The bad thing about that is every application running under tomcat will have access to it. You could set a property named base.persist.dir and build subdirectories for each application underneath it. We set system properties in the setenv.sh script in the bin/ directory under the CATALINA_OPTS environment variable.

like image 67
Andy Gherna Avatar answered Sep 28 '22 20:09

Andy Gherna