简体   繁体   中英

Best Practice for Location of Java JSP Application Files in Tomcat Environment

My Java JSP application requires to store permanent files on the Tomcat web server. At the moment I save the files in the "/temp" folder of the System. But this folder gets cleared from time to time. Further, the current solution is hard-coded which makes it less flexible (eg when moving to another server).

I would like to now if there is a best practice for defining and accessing a permanent directory in this configuration. In detail, where is the best place to define the app file directory, and how would I access this from within my java application? The goal of this setup would be to cause the least effort when (a) updating the application (ie placing a new war file), and (b) moving from one server to another and OS (eg Unix, Windows, MacOS).

The research I have done on this topic so far revealed that the following would be solutions (possibly amongst others):

1.) Use of a custom subdirectory in the Tomcat installation directory.

  • What happens to the files if I deploy a new version on the tomcat via war file?
  • Where do I define this directory to be accessed from within my Java application?

2.) In a separate directory in the file system.

  • Which are good locations or ways to get the locations without knowing the system?
  • Where do I define this directory to be accessed from within my Java application?

Thank you for your advice!

Essentially, you are creating 'a database' in the form of some files. In the world of Java EE and servlet containers, the only really general approach to this is to configure such a resource via JNDI. Tomcat and other containers have no concept of 'a place for persistent storage for webapps'. If a webapp needs persistent storage, it needs to be configured via JNDI, or -D, or something you tell it by posting something to it. There's no convention or standard practice you can borrow.

You can pick file system pathname by convention and document that convention (eg /var/something on Linux, something similar on Windows). But you won't necessarily be aligned with what anyone else is doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM