Thursday, 3 January 2013

Dynamic Deployment (Hot Deployment) of Web Application on Tomcat

Dynamic Deployment (Hot Deployment) of Web Application on Tomcat

Dynamic Deployment of Web Application on Tomcat

 

In order to deploy an application on Tomcat server we need to build a WAR file, upload it and deploy the web application. When it comes to development environment, it becomes a tedious process to build a WAR file and deploy it again and again as we make changes to our application. In this perspective, the Dynamic Deployment of Web Application is very helpful in development environments for Developers.

Instead of deploying a WAR file, the web application deployment can also be done using a Context File. The following are the steps to be followed for accomplishing it.

Step 1: Create a context file and drop it inside {CATALINA_HOME}\ conf\Catalina\localhost folder.

** {CATALINA_HOME} represents the Tomcat Home Directory

A Simple Context File   

struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<Context  docBase="D:/WS/STRUTS2/WebContent"  path="/struts"  />

Here  docBase represents the base directory of web application having the Tomcat Web Application Directory Structure and path represents the Context Path.

Tomcat Web Application Directory Structure

If you have any JNDI resources configured in Tomcat Server, we need to add them inside the context file as follows

Interflora.xml

<?xml version="1.0" encoding="UTF-8"?>

<Context

  docBase="D:\WS\sample

  path="/sample"  >

 

<Resource name="jdbc/sampleDS"

   auth="Container"

   type="oracle.jdbc.pool.OracleDataSource"

   driverClassName="oracle.jdbc.driver.OracleDriver"

   factory="oracle.jdbc.pool.OracleDataSourceFactory"

   url="jdbcURL"

   user="username"

   password="password"

   maxActive="20"

   maxIdle="10"

   maxWait="-1" />

</Context>

Here Database Connection details are configured inside Tomcat as JNDI resource.

Drop the Context file inside {CATALINA_HOME}\ conf\Catalina\localhost folder as follows and restart the Tomcat Server.

Whenever you make any changes in the application just run the ANT/Maven build, which in turn reflects the changes in the Tomcat Server as well.

 

Note: You need to restart the server if you make any changes to xml/properties files and optionally for java files as well.

The below screen shot shows that the application deployed on server using context file rather than a WAR file

2 comments: