Search code examples
tomcat7war

Tomcat 7 not auto unpacking war


I want to deploy my app as root app so I renamed my war to ROOT.war. Default server.xml looks like -

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

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

I also need to serve some static content. So I added Context tag-

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

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <Context docBase="/home/athakur/Documents/UI" path="/" />

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

I want to serve static content from this path and apis from my ROOT.war. But as soon as I add context element ROOT.war is not expanding and getting deployed. When I remove the context path it does. Also UI is correctly rendered from the path post adding context tag. So don't want to change that behavior either.


Solution

  • Looks like we cannot do this. We cannot have two context with same path and different docBase under same host. So you cannot have -

    <Context docBase="/home/athakur/Documents/UI" path="/" />
    <Context docBase="ROOT" path="/" />
    

    So I had to settle for

    <Context docBase="/home/athakur/Documents/UI" path="/" />
    <Context docBase="ROOT" path="/apis" />
    

    If you however want to do it at root level only then you need to do it from inside your webapp. Docs - https://tomcat.apache.org/tomcat-8.0-doc/config/context.html