Hello there,
I am using Tomcat 6, Apache Ant 1.7.1 and JDK 1.6 on OS X Snow Leopard...
Created the following build script and supporting property files:
(1) build.xml
<?xml version="1.0"?>
<project name="${project.name}" default="deploy" basedir=".">
<property file="build.properties"/>
<property file="admin.properties"/>
<taskdef file="tomcatTasks.properties">
<classpath>
<pathelement path="${tomcat.home}/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<target name="prepare">
<mkdir dir="${webapp.build.dir}" />
<mkdir dir="${webapp.build.dir}/WEB-INF" />
<mkdir dir="${webapp.build.dir}/WEB-INF/lib" />
<mkdir dir="${webapp.build.dir}/WEB-INF/classes" />
</target>
<target name="static" depends="prepare">
<!-- Copy web files -->
<copy todir="${webapp.build.dir}/">
<fileset dir="web" />
</copy>
<!-- Copy webapp configuration files -->
<copy todir="${webapp.build.dir}/WEB-INF/">
<fileset dir="etc" />
</copy>
<!-- Copy properties files -->
<copy todir="${webapp.build.dir}/WEB-INF/classes">
<fileset dir="props" />
</copy>
<!-- Copy jar files -->
<copy todir="${webapp.build.dir}/WEB-INF/lib/">
<fileset dir="lib" />
</copy>
</target>
<target name="compile" depends="static">
<javac srcdir="src"
destdir="${webapp.build.dir}/WEB-INF/classes/"
deprecation="off" debug="on" optimize="off">
<classpath>
<!-- Include all JAR files in my local library -->
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<!-- Include all common libraries in Tomcat -->
<fileset dir="${tomcat.home}/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="deploy" depends="compile">
<jar jarfile="${build.dir}/${webapp.name}.war" basedir="${webapp.build.dir}" />
<!-- Copy the newly built WAR file into the deployment directory -->
<copy file="${build.dir}/${webapp.name}.war" todir="${tomcat.deployment.dir}" />
</target>
<target name="clean" description="Clears all generated files, including build directories, distributables, and documentation.">
<delete dir="${build.dir}"/>
</target>
<target name="package">
<jar jarfile="${build.dir}/${webapp.name}.war" basedir="${webapp.build.dir}" />
</target>
<target name="install" description="Install application in Tomcat" depends="package">
<deploy url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"
war="file:${tomcat.deployment.dir}/${webapp.name}.war"/>
</target>
<target name="undeploy" depends="clean" description="Remove application in Tomcat">
<undeploy url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="/${webapp.name}"/>
</target>
</project>
(2) admin.properties:
tomcat.server=localhost
tomcat.manager.url=http://${tomcat.server}:8080/manager
tomcat.username=admin
tomcat.password=admin
(3) build.properties:
project.name=myproject
build.dir=./build
# Web app properties for the project
webapp.name=myproject
webapp.build.dir=${build.dir}/${webapp.name}
webapp.virtual.host=localhost
webapp.meta.dir=${webapp.build.dir}/META-INF
# Tomcat properties
tomcat.home=/Users/myuser/DevTools/Java/tomcat/apache-tomcat-6.0.20
tomcat.deployment.dir=${tomcat.home}/webapps
(4) tomcatTasks.properties:
# Tomcat Task Properties
deploy=org.apache.catalina.ant.DeployTask
install=org.apache.catalina.ant.InstallTask
list=org.apache.catalina.ant.ListTask
reload=org.apache.catalina.ant.ReloadTask
remove=org.apache.catalina.ant.RemoveTask
resources=org.apache.catalina.ant.ResourcesTask
roles=org.apache.catalina.ant.RolesTask
start=org.apache.catalina.ant.StartTask
stop=org.apache.catalina.ant.StopTask
undeploy=org.apache.catalina.ant.UndeployTask
(5) tomcat-users.xml:
When I run the deploy target, everything works (it places myproject.war) underneath $CATALINA_HOME/webapps...
However, when I run the undeploy target, I get the following error message:
Problem:
Buildfile: /Users/myuser/work/myproject/build.xml
Trying to override old definition of datatype resources
clean:
[delete] Deleting directory /Users/myuser/work/myproject/build
undeploy:
BUILD FAILED
/Users/myuser/work/myproject/build.xml:83: java.io.IOException: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/undeploy?path=/myproject
Total time: 170 milliseconds
Would really appreciate it if someone could tell me what I am doing wrong...
Thank you for taking the time to read this...
Happy programming.