tomcat的任务需要管理者的用户名和密码
即在tomcat-users.xml加入
<user username="admin" password="admin" roles="admin,manager"/>
一行,表明创建一个admin用户,它的角色是admin,manager
以下tomcat中的属性定性:(tomcatTasks.properties)
deploy=org.apache.catalina.ant.DeployTask
undeploy=org.apache.catalina.ant.UndeployTask
remove=org.apache.catalina.ant.RemoveTask
reload=org.apache.catalina.ant.ReloadTask
start=org.apache.catalina.ant.StartTask
stop=org.apache.catalina.ant.StopTask
list=org.apache.catalina.ant.ListTask
引入tomcat的任务属性文件:
<taskdef file="tomcatTasks.properties">
<classpath>
<pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
引用tomcatTasks.properties中install,即调用 org.apache.catalina.ant.deploy(deploy布署)
<target name="install" description="Install application in Tomcat"
depends="war">
<deploy url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${webapp.name}"
war="file:${dist.dir}/${webapp.name}.war"/>
</target>
移除tomcat中的应用程序,即调用 org.apache.catalina.ant.undeploy
<target name="remove" description="Remove application from Tomcat">
<undeploy url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${webapp.name}"/>
</target>
reload,start,stop和list任务也相似
<target name="reload" description="Reload application in Tomcat">
<reload url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${webapp.name}"/>
</target>
<target name="start" description="Start Tomcat application">
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${webapp.name}"/>
</target>
<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${webapp.name}"/>
</target>
<target name="list" description="List Tomcat applications">
<list url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password}"/>
</target>