Hi All,
I have written my first Ant script from scratch, using google and the
O'reilly definitive guide. I'm mostly happy with what I have ended up with,
however when I try to use the Tomcat DeployTask my application is not
deployed as expected.
If I manually copy my war file to the webapps directory everything is fine,
so I really would like to understand how to use ant to deploy using the
Tomcat task (rather than copying directly to the webapp folder - it seems
cleaner).
The files created after running the DeployTask are...
{webapps}/ciderbob-website/ciderbob-website.war
{webapps}/ciderbob-website/com/ciderbob/dao/*.class
{webapps}/ciderbob-website/com/ciderbob/tags/*.class
(note none of my jsp files or images are present!)
Why did it put ciderbob-website.war INSIDE a ciderbob-website directory? Or
more to the point, why does Tomcat not expand all of the contents? If I
manually copy the war file to {webapps} it all works properly!!?!
Here is my full ant build file...
Any help would be very much appreciated.
Cheers,
Rob.
<?xml version="1.0" encoding = "UTF-8"?>
<project name="ciderbob-common" default="build" basedir=".">
<property name="src" location="./src"/>
<property name="deploy" location="./deploy"/>
<property name="warfile" location="${deploy}/ciderbob-website.war"/>
<property name="web-lib.dir" location="./libs" />
<property name="common-lib" location="../common/bin/lib"/>
<property name="webcontent.dir" location="./WebContent"/>
<property name="web-inf.dir" location="${webcontent.dir}/WEB-INF"/>
<property name="meta-inf.dir" location="${webcontent.dir}/META-INF"/>
<property name="local.manager.url" value="http://localhost:8080/manager"/>
<property name="local.manager.username" value="admin"/>
<property name="local.manager.password" value="yeaRight!"/>
<property name="local.deploy.path" value="/ciderbob-website"/>
<property name="local.war" value="file://${deploy}/"/>
<target name="deploy-local" depends="build">
<!--
You must copy the server/lib/catalina-ant.jar from Tomcat 5
directory into the lib directory of your Ant installation to
use these tasks. (also had to add to eclipse ant path!?)
Also requires manager privileges with Tomcat - edit
conf/tomcat-users.xml to add manager privileges for a username
and password.
-->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
<undeploy url="${local.manager.url}"
username="${local.manager.username}"
password="${local.manager.password}"
path="${local.deploy.path}" failonerror="no"/>
<!-- this results in the following files being created
{webapps}/ciderbob-website/ciderbob-website.war
{webapps}/ciderbob-website/com/ciderbob/dao/*.class
{webapps}/ciderbob-website/com/ciderbob/tags/*.class
Why did it put ciderbob-website.war INSIDE a ciderbob-website
directory? Or more to the point, why does Tomcat not expand all of
the contents? If I manually copy the war file to {webapps} it all
works properly!!?!
-->
<deploy url="${local.manager.url}"
username="${local.manager.username}"
password="${local.manager.password}"
path="${local.deploy.path}"
localWar="${local.war}"
alwayslog="yes"
/>
<reload url="${local.manager.url}"
username="${local.manager.username}"
password="${local.manager.password}"
path="${local.deploy.path}"/>
</target>
<target name="build" depends="Initialize, Compile, War">
<echo message="Building..."/>
</target>
<target name="Initialize">
<echo message="Initialising..."/>
<delete dir="${deploy}"/>
<mkdir dir="${deploy}"/>
</target>
<path id="classpath">
<fileset dir="${common-lib}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${web-lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<echo message="Classpath... ${classpath}"/>
<target name="Compile" depends="Initialize">
<depend srcDir="${common-lib}">
</depend>
<echo message="Compiling..."/>
<javac srcdir="${src}" destdir="${deploy}" includes="**/*.java"
excludes="**/Test*.java">
<classpath refid="classpath"/>
</javac>
</target>
<target name="War" depends="Initialize, Compile">
<echo message="Generating War file..."/>
<war destfile="${warfile}" webxml="${web-inf.dir}/web.xml">
<classes dir="${src}" includes="**/*.xml" />
<classes dir="${deploy}" includes="**/*.class" />
<fileset dir="${webcontent.dir}">
<include name="**/*"/>
</fileset>
<lib dir="${web-lib.dir}" includes="**/*.jar" />
<lib dir="${common-lib}" includes="**/*.jar" />
</war>
</target>
</project>