Apache Tomcat Deploy web application

How to deploy web application on Apache Tomcat using Context file? This is the most flexible and recommended way.

How to deploy some web application to Apache Tomcat? The easiest way is to copy a WAR file to webapps directory. Or using a Tomcat manager. I covered these in a previous tutorial.


The most flexible and recommended way is to create a Context file. For example let's create a ROOT.xml file with this contents:


<?xml version='1.0' encoding='utf-8'?>
<Context docBase="c:/tomcat/eshop-web.war">


Name of the file will be the path of your web application and inside the Context file must be location of your web application.


I will use a web application from my GitHub account where I have lot's of example open source web applications for Java programmers.


To deploy this web application, first make sure you already don't have ROOT application in webapps directory. Next copy ROOT.xml to [apache-tomcat]/conf/Catalina/localhost. This will trigger deployment and your application will be deployed as a default web application. To undeploy this web application, simply remove ROOT.xml file, which will trigger the undeploy process.