Saturday, April 27, 2013

In addition to the ability to execute Manager commands via HTTP requests. Tomcat includes a convenient set of Task definitions for the Ant (version 1.4 or later) build tool. In order to use these commands, you must perform the following setup operations:

  • Download the binary distribution of Ant from http://ant.apache.org. You must use version 1.4 or later.
  • Install the Ant distribution in a convenient directory (called ANT_HOME in the remainder of these instructions).
  • Copy the file server/lib/catalina-ant.jar from your Tomcat installation into Ant's library directory ($ANT_HOME/lib).
  • Add the $ANT_HOME/bin directory to your PATH environment variable.
  • Configure at least one username/password combination in your Tomcat user database that includes the manager-script role.
To use custom tasks within Ant, you must declare them first with a <taskdef> element. Therefore, your build.xml file might look something like this:
build.xml

<project name="MyApp" default="deploy" basedir=".">
<!-- loading properties file. -->
<property file="tomcatdeploy.properties"/>
<property name="src" location="${basedir}/src"/>
<property name="webcontent" location="${basedir}/WebContent"/>
<property name="lib" location="${webcontent}/WEB-INF/lib"/>
<!-- Configure the directory into which the web application is built -->
<property name="build" value="${basedir}/build"/>
<property name="war" location="${basedir}/war"/>
<!-- Configure the context path for this application -->
<property name="path" value="/myapp"/>
<!-- Configure properties to access the Manager application -->
<property name="url" value="${manager.url}"/>
<property name="username" value="${manager.username}"/>
<property name="password" value="${manager.password}"/>

<!-- Configure the custom Ant tasks for the Manager application -->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask"/>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/>
<taskdef name="findleaks" classname="org.apache.catalina.ant.FindLeaksTask"/>
<taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask"/>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>

<path id="libpath">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>

<target name="clean" description="Deleting build and war directories">
<delete dir="${build}"/>
<delete dir="${war}"/>
</target>

<target name="init" depends="clean" description="Creating build and war directories">
<mkdir dir="${build}"/>
<mkdir dir="${war}"/>
</target>

<target name="compile" depends="init" description="Compile web application">
<copy todir="${build}/">
<fileset dir="${webcontent}"/>
</copy>
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}/WEB-INF/classes" classpathref="libpath" includeantruntime="true"/>
</target>

<target name="war" depends="compile" description="generate the distribution war" >
<jar jarfile="${war}${path}.war" basedir="${build}"/>
</target>

<target name="deploy" description="Install web application" depends="war">
<deploy url="${url}" username="${username}" password="${password}" path="${path}" war="file:${war}${path}.war"/>
</target>

<target name="reload" description="Reload web application">
<reload  url="${url}" username="${username}" password="${password}" path="${path}"/>
</target>

<target name="undeploy" description="Remove web application">
<undeploy url="${url}" username="${username}" password="${password}" path="${path}"/>
</target>

</project>

tomcatdeploy.properties


manager.url = http://localhost:8080/manager/text
manager.username = tomcatusername
manager.password = tomcatpassword



Donot forget to give your comments /suggestions and refer to your friends.

No comments:

Post a Comment