1
votes

Trying to get a Tomcat 7 application off the ground and know a couple of things:

  1. In earlier versions of Tomcat the content of a Context Descriptor configuration was often stored within Tomcat's primary configuration file server.xml but this is now discouraged (although it currently still works).

  2. The locations for Context Descriptors are: $CATALINA_BASE/conf/[enginename]/[hostname]/[webappname].xml $CATALINA_BASE/webapps/[webappname]/META-INF/context.xml

So here is the way our apps are laid out (non-negotiable):

Tomcat + WAR: /some/dir/MyApp/* some/dir/MyApp/webapps
LOGS: /some/other/dir/logs/MyApp/

After the app starts with no errors I make requests for:

http://foo/static/index.html

When I define the context in $CATALINA_HOME/conf/server.xml everything is beautiful:

<Host name="localhost"  appBase="webapps"
   unpackWARs="false" autoDeploy="true">

    <Context path="/" docBase=“MyApp.war" />

    <Valve className="org.apache.catalina.valves.AccessLogValve"
           directory="/some/other/dir/logs/MyApp"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>

Now to avoid putting the context in server.xml here are a couple of things i tried. I removed the context from server.xml then created a $CATALINA_HOME/conf/Catalina/localhost/MyApp.xml file.

<Context
  docBase=“/some/dir/MyApp/webapps/MyApp.war"
  path=""
  reloadable="false"
  swallowOutput="true"
  sendRedirectBody="true"
>
  <Valve className="org.apache.catalina.valves.AccessLogValve"
   prefix="localhost_access_log." suffix=".txt"
   pattern="common"/>
</Context>

-->FAIL: 13/Jun/2014:17:03:53 -0700] "GET /static/index.html HTTP/1.1" 404 -

-->MyApp.log: A docBase /some/dir/MyApp/webapps/MyApp.war inside the host appBase has been specified, and will be ignored

Next I tried removing the context from server.xml, deleting $CATALINA_HOME/conf/Catalina/localhost/MyApp.xml, but creating $CATALINA_HOME/conf/context.xml:

<Context>
    path = ""
    docBase=“MyApp.war"
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

—>FAIL: 13/Jun/2014:17:03:53 -0700] "GET /static/index.html HTTP/1.1" 404 -

I tried the above context.xml with and without the path, and docBase defined with both producing the same 404.

What am I missing?

1
WHy are you mucking about with context paths? Why not just let Tomcat handle that, and throw a reverse proxy (like nginx) in front.Mikkel Løkke

1 Answers

2
votes

You should not even need to manually define a context. If you want your app to be deployed on the root, simply rename your war to ROOT.war and put it in webapps directory (deleting all occurences).

Tomcat looks into the webapps directory (actually, it can be changed by the appBase attribute on the Host) to deploy war.

See tomcat Documentation for more details.