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.

Sunday, April 21, 2013

Setting Global Environment Variables in CentOS


The easiest way to set an environment variable in CentOS is to use export as in

$> export JAVA_HOME=/usr/java/jdk.1.5.0_12

$> export PATH=$PATH:$JAVA_HOME

However, variables set in such a manner are transient i.e. they will disappear the moment you exit the shell. Obviously this is not helpful when setting environment variables that need to persist even when the system reboots.

In such cases, you need to set the variables within the system wide profile. In CentOS (I’m using v5.2), the folder /etc/profile.d/ is the recommended place to add customizations to the system profile.

For example, when installing the Sun JDK, you might need to set the JAVA_HOME and JRE_HOME environment variables. In this case:

Create a new file called java.sh
vim /etc/profile.d/java.sh

Within this file, initialize the necessary environment variables
export JRE_HOME=/usr/java/jdk1.5.0_12/jre
export PATH=$PATH:$JRE_HOME/bin

export JAVA_HOME=/usr/java/jdk1.5.0_12
export JAVA_PATH=$JAVA_HOME

export PATH=$PATH:$JAVA_HOME/bin

Now when you restart your machine, the environment variables within java.sh will be automatically initialized (checkout /etc/profile if you are curious how the files in /etc/profile.d/ are loaded) .

PS: If you want to load the environment variables within java.sh without having to restart the machine, you can use the source command as in:

$> source java.sh