tomcatweb-applicationsconfigurationweb-inf

Can you have WEB-INF outside the webapp?


An externally provided war-file includes its configuration inside the WEB-INF directory. I'm trying to make Tomcat provide the web-app with an alternate WEB-INF directory, so I can put the configuration under version control and not have to modify the war-file. New versions of the war-file will be supplied periodically.

So, what I want to do, is to copy the WEB-INF contents outside of Tomcat, put it under version control, and then tell Tomcat (8 for now, but we may switch to 7) to use that external directory as its WEB-INF. That way, a new deploy will automatically use the old configuration and changes to the configuration will not be lost.

(I'm actually planning on having the configuration as a separate deployable/"webapp" and let jenkins handle that, so nobody ever has to access the server userspace directly. But that's irrelevant to the question, I think)

I have looked around some and my best ideas seem to center around the Context and Resources supplied by Tomcat, but I'm not certain this is actually possible.

$CATALINA_BASE/conf/[enginename]/[hostname]/[webappname].xml

These files can supply external configuration for specific apps, so I'm thinking that's the place to start. Here's my attempt:

<Context>
  <Resources>
    <PreResources className="org.apache.catalina.webresources.DirResourceSet"
                  base="/home/tomcat/webapps/config/conf" webAppMount="/WEB-INF" />
  </Resources>
</Context>

I've tried another directory as well, outside of webapps, but it didn't work either. Anyone know why it doesn't work? Is this just a pipe dream, will I be forced to either alter the war-files or do the maintainer-recommended deploy-stop-"patch in" config-start?


Solution

  • It seems the above works fine. I'd just put one letter in the base path as lower rather than upper case.

    One of those cases when the problem was solved the moment another person took a look at what I'd actually written.

    Mods; feel free to either delete the question altogether or just leave it be as a how-to post for someone looking for how to solve the same problem in the future.