Tuesday, October 30, 2012

Various ways of deploying to Tomcat

Below are the various possibilities we can deploy a web-application in Tomcat:

  • By setting autoDeploy to true at the host in server.xml, we can copy either copy the war file or unpacked directory structure onto the folder configured against appBase.  The application context would be either war name or the directory name.

  • Configure <Context> element in server.xml under <Host> element
        ...
        ...
        <Context path="/myApp" docBase="/myFolder" reloadable="true" />
      </Host>
    </Engine>
  </Service>
</Server>

The application context would be myApp

  • Write a configuration file with a <Context> element and place it under "conf\Catalina\localhost"
Sample myApp.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="Path_to_folder" path="/myApp" />

The application context would be  myApp

The context path can also be explicitly set in case of WAR files by packaging context.xml under META-INF within war.

No comments: