Deploying to Tomcat
Tomcat (available from http://jakarta.apache.org/tomcat/), the reference Web server for servlets and JSP, has become more attractive to Ant developers since it comes with custom Ant tasks for deployment. Copy the file server/lib/catalina-ant.jar from your Tomcat 5 installation into the lib directory of your Ant installation to use these tasks.
The Tomcat deployment tasks are deploy, reload, and undeploy; to use them, add these taskdef elements (discussed in Chapter 11) to your build file:
<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"/>
To use these tasks, you'll need manager privileges with
Tomcat; edit conf/tomcat-users.xml to add manager
privileges for a username (admin
here) and password like this:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="role1"/>
<role rolename="tomcat"/>
<user username="admin" password="password" roles="manager"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
</tomcat-users>You can use the deploy
task to deploy a web application to Tomcat from Ant like this:
<target name="install"> <deploy url="${manager.url}" username="${manager.username}" password="${manager.password}" path="${app.path}" ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access