Tomcat Ant Tasks

原创 2005年04月24日 21:26:00

TomcatAntTasks Search Wiki:   
Your trail: 

--------------------------------------------------------------------------------

I finally figured out how to use Tomcat's Ant Tasks (install, remove, reload, start, stop, list) in AppFuse to ease deployment of the app. Below is a list of of the steps I used to integrate them into my build.xml file.

1. Rather than defining each task with a <taskdef>, I created a tomcatTasks.properties file with the following contents:

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

2. Then I created a tomcat.properties file with the following contents. Make sure the $CATALINA_HOME/conf/tomcat-users.xml file has an entry with username/password admin/admin and that they have the manager role.

# Properties for Tomcat Server
tomcat.server=localhost
tomcat.manager.url=http://${tomcat.server}:8080/manager
tomcat.username=admin
tomcat.password=admin     

3. I included a reference to tomcat.properties in my build.xml file:

<property file="tomcat.properties"/>

4. Then I added all a single taskdef and all the targets/tasks I wanted to use to my build.xml file:

    <taskdef file="${ant-contrib.dir}/tomcatTasks.properties">
        <classpath>
            <pathelement path="${tomcat.home}/server/lib/catalina-ant.jar"/>
        </classpath>
    </taskdef>
    <target name="install" description="Install application in Tomcat"
        depends="package-web">
        <deploy url="${tomcat.manager.url}"
            username="${tomcat.username}"
            password="${tomcat.password}"
            path="/${webapp.name}"
            war="file:${webapp.dist}/${webapp.war}"/>
    </target>

    <target name="remove" description="Remove application in Tomcat">
        <undeploy url="${tomcat.manager.url}"
            username="${tomcat.username}"
            password="${tomcat.password}"
            path="/${webapp.name}"/>
    </target>

    <target name="reload" description="Reload application in Tomcat">
        <reload url="${tomcat.manager.url}"
            username="${tomcat.username}"
            password="${tomcat.password}"
            path="/${webapp.name}"/>
    </target>

    <target name="start" description="Start Tomcat application">
        <start url="${tomcat.manager.url}"
            username="${tomcat.username}"
            password="${tomcat.password}"
            path="/${webapp.name}"/>
    </target>

    <target name="stop" description="Stop Tomcat application">
        <stop url="${tomcat.manager.url}"
            username="${tomcat.username}"
            password="${tomcat.password}"
            path="/${webapp.name}"/>
    </target>

    <target name="list" description="List Tomcat applications">
        <list url="${tomcat.manager.url}"
            username="${tomcat.username}"
            password="${tomcat.password}"/>
    </target>

NOTE: There are a few things I discovered in this process:


If you put a context.xml file in your WAR's META-INF directory, the deploy task will recognize it and use it. This is the same as defining your context in server.xml or putting an appname.xml file in $CATALINA_HOME/webapps. In Tomcat 4, this only works with the deploy task. In Tomcat 5, this will work with any war - even if you just drop it into $CATALINA_HOME/webapps.


That's a very slick feature IMO. Now if there was only a way to deploy the JDBC Driver with the WAR and have it auto-deployed to $CATALINA_HOME/common/lib.


All these tasks will overwrite your server.xml file in Tomcat 4.1.x. They do create a backup, but if you're having configuration issues after using these, revert back to your original server.xml. I've included a minimal server.xml for Tomcat 4.1.29. Also, the war is deployed under the $CATALINA_HOME/work/Standalone/localhost/manager directory.
In Tomcat 4.1.x, the reload target doesn't work with WARs. You have to use "ant stop start" to simulate a reload.

The good news is that all of the issues that occur in Tomcat 4.1.x are gone in Tomcat 5.


In Tomcat 5, the server.xml is not overwritten. The context.xml is extracted where you would expect it ($CATALINA_HOME/conf/Catalina/localhost), and the WAR is deployed (and expanded) to the webapps directory.
The reload target works in Tomcat 5 - providing you don't have any non-serializeable attributes in your session.


Attachments:
server-minimal-4.1.29.xml  2693 bytes
server-minimal-5.0.16.xml  1680 bytes

[Ant] 创建并调试自定义的Ant Task

自定义Ant Task的实现,调用,及调试。
  • CaesarZou
  • CaesarZou
  • 2010年06月15日 15:51
  • 7799

使用Ant发布web应用到tomcat

使用Ant发布web应用到tomcat         今天在公司用ant写了个部署web应用的脚本,闲来无事,就稍微总结一下,以供以后参照使用,也希望作为一个demo, 能对大家有启迪的作用,如果真...
  • hbcui1984
  • hbcui1984
  • 2007年12月19日 22:57
  • 7586

用ant启动和关闭tomcat

转贴至:http://www.javauu.com/thread-119-1-1.html  (一)linux 环境  (端口号应根据自己的tomcat配置,进行设置)A:启动TOMCAT      ...
  • youjianbo_han_87
  • youjianbo_han_87
  • 2009年08月17日 17:27
  • 3537

使用ANT脚本编译、打包、部署到tomcat,启动、停止tomcat

${build.time}
  • hardwin
  • hardwin
  • 2012年05月12日 20:47
  • 5369

ant 脚本里面启动、停止tomcat的两种方法

第一,在windows 命令行窗口显示tomcat控制台界面  停止tomcat -->
  • hardwin
  • hardwin
  • 2012年05月12日 20:45
  • 9549

tomcat 与Ant工具

Tomcat提供了图像用户界面控制台,用户可以方便的部署Web应用,监控Web应用的状态 Tomcat控制台提供两种方式部署Web应用:一种是将整个目录部署成Web应用,另一种是将WAR文件部署成W...
  • renyuanchunby
  • renyuanchunby
  • 2011年12月05日 17:13
  • 3187

自定义Ant Task

在ant打包的时候老是忘记把manifest.xml中的android:debugable改为false,后来干脆自定义个task来修改这项 官方的Turtorialhttp://ant.apache...
  • pipisky2006
  • pipisky2006
  • 2011年08月11日 22:56
  • 4160

Ant+Tomcat自动部署

今天研究对象是Ant,用于对msms系统进行Tomcat的自动部署。遇到一个怪问题,百思不得其解:通过ant depoly可以把msms.war部署到tomcat上。当然,要求这时候webapps下面...
  • yxfei666
  • yxfei666
  • 2010年08月06日 17:01
  • 4369

ant 问题解决

android ant 打包
  • lizhongyisailang
  • lizhongyisailang
  • 2015年05月18日 15:20
  • 1049

ant编译tomcat

安装jdk,用jdk6即可,如果要编译JSR-356 (Java WebSocket 1.1)则需要jdk7. 安装ant,Ant 1.8.2或更新版本。 连到apache的svn上下载自己想要的版本...
  • wangyangzhizhou
  • wangyangzhizhou
  • 2017年02月06日 15:55
  • 1136
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Tomcat Ant Tasks
举报原因:
原因补充:

(最多只允许输入30个字)