1

I am working on an old Java web application that runs on Tomcat. I know that typically you run web apps from the webapps directory which uses Tomcat's default server configuration (server.xml). This particular app is deployed to a different directory using a custom server.xml so it requires 1 tomcat instance per app. I believe the reason it was initially setup that way is due to the fact that each web app produces files that must be saved between redeploys of the application.

My question is - is there a way to use the webapps directory but also save certain files from being wiped out during a redeploy of the application?

Here's the layout of our current tomcat

tomcat/
  servers/
    ourapp/
      output/   # heres where the files go that we save
      ourapp/   # this is the actual webapp (exploded WAR file)
        WEB-INF/
        ...

I want something like

tomcat/
  webapps/
    ourapp/
      output/  # but this is saved between redeploys
      WEB-INF/
    ...

My end goal is to get away from custom server.xml's so we deploy multiple apps on one tomcat instance. Just in case in matters - we're on Tomcat 6.

jeff
  • 4,325
  • 16
  • 27

2 Answers2

4

I'd recommend not trying to store those files in webapps/ if you want them persisted. That directory is pretty volatile. Additionally, other developers maintaining the system may not realize you've stored persistent data there and might just wipe it accidentally.

I'd go for a location in /var/lib, perhaps /var/lib/ourapp/.... Or you could store it in $HOME/.ourapp if that make sense for your server environment and how it's managed.

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
  • +1; "permanent" files should be stored in a configurable location. These files can be streamed, symlinked, etc. – Dave Newton Apr 17 '12 at 15:22
  • @DaveNewton - Agreed on the configuration. I usually use a property file or a system property to define a location for storage. – Rob Hruska Apr 17 '12 at 15:24
  • Cool - thanks guys. That makes sense. I'll accept as soon as the 10 min is up. – jeff Apr 17 '12 at 15:27
  • @jeff - You don't have to accept it immediately; others might have good alternative ideas if you give it some time. – Rob Hruska Apr 17 '12 at 15:28
  • @user384706 - People aren't as likely to come by and just remove something in `/var`. With the `webapps/` directory though, it can be commonplace to wipe the extracted war directory and/or war file on an upgrade or redeployment. People don't expect persistent data to be there; it violates the [principle of least astonishment](http://en.wikipedia.org/wiki/Principle_of_least_astonishment). – Rob Hruska Apr 17 '12 at 15:29
  • @RobHruska:Ok perhaps not in `webapps` but I would suggest inside Tomcat.It seems more natural there (at least to me) and you can never be sure what is going to happen to `/var` by a dummy user – Cratylus Apr 17 '12 at 15:32
  • @user384706 - I understand the argument, although still partially disagree (see my comment on your answer). `/var`'s a [standard](http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/c23.html) place for application data - if someone's on my production system randomly messing with things under `/var`, they'd be entering a world of pain. Also, consider MySQL, which uses `/var/lib/mysql` for its data. Would you make the same argument for its storage? The data's got to go somewhere - might as well use standard directories. – Rob Hruska Apr 17 '12 at 15:40
  • @RobHruska:ok, I'll buy it :) – Cratylus Apr 17 '12 at 15:52
0

I would suggest that you save your files under Tomcat (could be outside or inside webapps) and not in a random dir in the filesystem.
This way it is "bundled" with your webapp in a way

Cratylus
  • 52,998
  • 69
  • 209
  • 339
  • 1
    I agree that it's nice to have things near to each other, but IMO a directory under `$TOMCAT_HOME` would be more arbitrary than a location like `/var/ourapp` or `$HOME/.ourapp`. Those directories are standard linux locations for application data. It also depends on how Tomcat was installed. If it was done via RPM, Tomcat would probably be installed into `/usr` somewhere, which would be an awkward place to store persistent application data. See the [Linux Filesystem Hierarchy](http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/c23.html). – Rob Hruska Apr 17 '12 at 15:35