How to Host Web Application on Tomcat?

Web Application can be configured and host in different ways mainly there is only two ways by which we can configure our Web Application to Any Tomcat versions, By following ways we can do that:
1. Copy your Application file/WAR files or your web application’s directory to the $CATALINA_BASE/webapps directory.

2. Create an XML fragment file with just the Context element for your web application, and place this XML file in$CATALINA_BASE/webapps. The web application itself can then be stored anywhere on your filesystem.
If you have a WAR file, you can deploy it by simply copying the WAR file into the directory CATALINA_BASE/webapps. The filename must end with an extension of “.war”. Once Tomcat notices the file, it will (by default) unpack it into a subdirectory with the base name of the WAR file. It will then create a context in memory, just as though you had created one by editing Tomcat’sserver.xml file. However, any necessary defaults will be obtained from the DefaultContext element in Tomcat’s server.xml file.

Another way to deploy a web app is by writing a Context XML fragment file and deploying it into the CATALINA_BASE/webapps directory. A context fragment is not a complete XML document, but just one Context element and any subelements that are appropriate for your web application. These files are like Context elements cut out of the server.xml file, hence the name “context fragment.”
For example, if we wanted to deploy the WAR file MyWebApp.war along with a realm for accessing parts of that web application, we could use this fragment:
<Context path=”/tekhnologia” docBase=”webapps/tekhnologia.war”
         debug=”0″ privileged=”true”>
  <Realm className=”org.apache.catalina.realm.UserDatabaseRealm”               
You can add above xml content to “tekhnologia.xml,” and copy it into your CATALINA_BASE/webapps directory.

These context fragments provide a convenient method of deploying web applications; you do not need to edit the server.xml file and, unless you have turned off the default liveDeploy feature, you don’t have to restart Tomcat to install a new web application.
If we have war file then we can also use tomcat GUI deployment application from Tomcat Manager.


If you like reading this please spare 5 second to comment or share it with others.