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

maven-ant-tasks-2.1.3-src

  • 2012年05月22日 12:35
  • 172KB
  • 下载

maven-ant-tasks.jar

  • 2011年04月22日 10:54
  • 958KB
  • 下载

Ant生成JunitReport(Writing Tasks )

1. What should Ant do for us? compiles my stuff: 编译文件 make the jar, so that I can deploy it: 编译生...

Ant Tasks1.6.0.pdf

  • 2009年08月23日 22:40
  • 1.41MB
  • 下载

Ant: 使用外部的tasks

如何使用外部tasks使用外部的tasks,做两步就行了: 把它们的实现放到Ant能找到的地方 声明它们第一步让Ant找到外部的libraries有三种方法通过命令行参数 -lib 放到 ${user...

使用 Flex Ant Tasks 构建 Flex 项目-第 I 部分:为 Flex 创建构建脚本

与其他开发人员在团队环境中合作时,必须并且最好实现应用程序构建流程的标准化。大多数大型企业项目借助源控制和自动化工具,使整个团队能使用相同代码并跟踪大量软件修订版,同时制作可重复的构建。许多 Java...

Overview of Apache Ant Tasks

Overview of Apache Ant Tasks Given the large number of tasks available with Ant, it may be difficul...
  • uper945
  • uper945
  • 2011年08月28日 21:48
  • 556

ant中使用maven-ant-tasks下载maven的依赖

ant中使用maven-ant-tasks下载maven的依赖

使用ant部署eclipse开发的web工程到tomcat

使用ant部署eclipse开发的web工程到tomcat文章分类:Java编程由于myeclipse体积的不断膨胀,搞的现在的开发很痛苦,一直在等它"活"过来,就算不计较效率了,人也忍受不了。所以觉...

jenkins+tomcat +ant +svn 搭建持续构建环境

需要的资料链接:http://pan.baidu.com/s/1jHL6bye 密码:17bf      Jenkins+ tomcat+ant+svn   工作原理图 Jenkins 简...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Tomcat Ant Tasks
举报原因:
原因补充:

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