`
iloveflower
  • 浏览: 79007 次
社区版块
存档分类
最新评论
  • iloveflower: 呵呵。好好学习。。。。。。。。。。。。
    java 读书
  • Eric.Yan: 看了一点,不过是电子版的……你这一说到提醒我了,还要继续学习哈 ...
    java 读书

Catalina-Ant for Tomcat 7

 
阅读更多
http://paulgrenyer.blogspot.co.uk/2011/11/catalina-ant-for-tomcat-7.html

I recently upgraded from Tomcat 6 to Tomcat 7 and all of my Ant deployment scripts stopped working. I eventually worked out why and made the necessary changes, but there doesn’t seem to be a complete description of how to use Catalina-Ant for Tomcat 7 on the web so I thought I'd write one.
1.To start with, make sure Tomcat manager is configured for use by Catalina-Ant. Make sure that manager-script is included in the roles for one of the users in TOMCAT_HOME/conf/tomcat-users.xml. For example:<tomcat-users>    <user name="admin" password="s3cr£t" roles="manager-gui,manager-script"/></tomcat-users>
2.Catalina-Ant for Tomcat 6 was encapsulated within a single JAR file. Catalina-Ant for Tomcat 7 requires four JAR files. One from TOMCAT_HOME/bin:

tomcat-juli.jar

and three from TOMCAT_HOME/lib:

catalina-ant.jar
tomcat-coyote.jar
tomcat-util.jar

There are at least three ways of making the JARs available to Ant:

1.Copy the JARs into the ANT_HOME/lib folder. Then Ant will just find them.

2.Copy the JARs to a folder within your project that you check into your source control system. Ant then needs a path id to find them:
<path id="catalina-ant-classpath">    <fileset dir="${catalina-ant-dir}">        <include name="catalina-ant.jar"/>        <include name="tomcat-coyote.jar"/>        <include name="tomcat-util.jar"/>        <include name="tomcat-juli.jar"/>    </fileset></path>Where catalina-ant-dir is the directory with the JARs in. This way you don’t need to modify the Ant installation on every machine you build on.

3.Access the JARs directly from your Tomcat 7 installation. Ant then needs a path id to find them:<path id="catalina-ant-classpath">    <fileset dir="${appserver.lib}">           <include name="catalina-ant.jar"/>           <include name="tomcat-coyote.jar"/>           <include name="tomcat-util.jar"/>        </fileset>    <fileset dir="${appserver.home}/bin">               <include name="tomcat-juli.jar"/>    </fileset></path>Where appserver.lib is the path to Tomcat 7’s lib directory and appserver.home is the path to Tomcat’s top level installed directory. This way Tomcat 7 is required on every box you build on.

My personal preference is for 2 above.

3.Now that your Ant script can see the Catalina-Ant JARs you need to tell it what tasks are available. These are most if not all of the tasks that are available to Ant.<taskdef name="catalina-deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-list" classname="org.apache.catalina.ant.ListTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-reload" classname="org.apache.catalina.ant.ReloadTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-findleaks" classname="org.apache.catalina.ant.FindLeaksTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-resources" classname="org.apache.catalina.ant.ResourcesTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-start" classname="org.apache.catalina.ant.StartTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-stop" classname="org.apache.catalina.ant.StopTask" classpathref="catalina-ant-classpath"/><taskdef name="catalina-undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="catalina-ant-classpath"/>
4.Finally you need a set of tasks that actually do the work. Although, as you can see above, there are a few tasks I only tend to use the following ones:
<target name = "stop-webapp">       <catalina-stop url="${tomcat.manager.url}"                         username="${tomcat.username}"                         password="${tomcat.password}"                         path="/${webapp.name}"                         failonerror="false"/></target><target name = "start-webapp">    <catalina-start url="${tomcat.manager.url}"                       username="${tomcat.username}"                       password="${tomcat.password}"                       path="/${webapp.name}"/></target><target name = "undeploy-webapp">    <catalina-undeploy url="${tomcat.manager.url}"                          username="${tomcat.username}"                          password="${tomcat.password}"                          path="/${webapp.name}"                          failonerror="false"/></target><target name = "deploy-webapp">    <catalina-deploy url="${tomcat.manager.url}"                        username="${tomcat.username}"                        password="${tomcat.password}"                        path="/${webapp.name}"                        war="file:${war.file}"/></target>
tomcat.manager.url is the URL where Tomcat manager lives. This is another of the changes from Tomcat 6 to Tomcat 7. Usually this will be: http://:8080/manager/text.

Tomcat.username and Tomcat.password are the user name and password for Tomcat manager.

webapp.name is the name of the Tomcat application that you are deploying.

war.file is the path the Tomcat application you are deploying’s WAR file.

The stop-webapp task has the failonerror attribute set to false as on most occasions you don’t want the Ant build to stop if a Tomcat application you’re trying to stop isn’t running.

I usually define all of these properties in a properties file that Ant can read. That way local settings can be picked up more easily if builds are run on different machines.


***************************************
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Deploy_A_New_Application_from_a_Local_Path
In this manual, it's not correct, you have to follow above steps to copy four jars not only one jar file mentioned in the document.
分享到:
评论

相关推荐

    tomcat-catalina-ant-7.0.30.zip

    【标题】"Tomcat Catalina Ant 7.0.30" Apache Tomcat 是一个流行的开源Web服务器和Java Servlet容器,主要用于部署和运行Java web应用程序。Catalina是Tomcat的核心组件,负责处理Servlet和JSP(JavaServer Pages...

    ant1-9-4和tomcat7-0-57包

    《Ant与Tomcat:开发工具与应用服务器的深度解析》 Ant和Tomcat是Java开发者在构建和部署Web应用程序时的两大关键工具。Ant是一种基于Java的构建工具,而Tomcat则是一个流行的开源Servlet和JavaServer Pages(JSP)...

    Ant编译Tomcat源码、MyEclipse导入Tomcat源码、执行Tomcat源码启动Tomcat

    下载并解压`apache-tomcat-6.0.37-src.zip`后,进入解压后的目录,通过命令行执行`ant`命令,Ant会根据`build.xml`中的配置编译源码,生成可执行的Tomcat服务器。 接下来,我们关注如何在MyEclipse集成开发环境中...

    精通Hibernate:Java对象持久化技术详解(第2版)源代码

    不包含jar文件。 成功运行所需的jar文件参照如下: (本人另一个上传资源里面也有 精通HibernateJava对象持久化技术详解(第2版)jar文件.zip) annotations-api.jar antlr-2.7.6.jar ...tomcat-i18n-ja.jar

    使用ANT远程发布Web项目

    1. **增加管理员用户**:编辑`conf\tomcat-users.xml`文件,添加如下配置: ```xml &lt;tomcat-users&gt; &lt;user name="admin" password="007" roles="admin-gui,manager-gui" /&gt; &lt;/tomcat-users&gt; ``` #### 四、执行...

    ant启动tomcat

    - `&lt;jvmarg value="-Dcatalina.home=${tomcat.home}"/&gt;`:设置环境变量`catalina.home`为Tomcat的安装目录路径。 2. **tomcat.stop**: - `&lt;target name="tomcat.stop"&gt;`:定义了名为“tomcat.stop”的目标。 -...

    ant启动关闭tomcat

    - **等待时间**:通过`&lt;waitfor&gt;`标签,我们可以指定Ant等待Tomcat完全停止的时间,避免因为进程未完全关闭而引发的问题。 ### 四、结论 通过上述配置,我们可以看到Ant提供了强大的功能来管理和控制Tomcat服务器...

    apache-tomcat-5.5.25-src.tar.gz

    在本文中,我们将深入探讨`apache-tomcat-5.5.25-src.tar.gz`这个源码包,它包含了Apache Tomcat 5.5.25版本的完整源代码。 Apache Tomcat 5.5.x系列是Tomcat的一个稳定版本,发布于2007年。它基于Java EE 5规范,...

    apache-tomcat-9.0.82-windows-x64.zip

    这个特定的压缩包文件“apache-tomcat-9.0.82-windows-x64.zip”包含了Tomcat服务器的第9.0.82版本,专为64位Windows操作系统设计。 Tomcat是Apache软件基金会Jakarta项目的一部分,它实现了Java EE的Web容器规范,...

    apache-tomcat-9.0.0.M20-src.tar.gz

    1. **解压**:首先,你需要使用解压工具(如7-Zip或WinRAR)解压"apache-tomcat-9.0.0.M20-src" 文件到你的本地目录。 2. **构建**:使用Java的构建工具,如Maven或Ant,来编译源代码。Tomcat项目通常使用Ant,但...

    apache-tomcat-8.5.56-src.tar.gz

    在本例中,我们讨论的文件"apache-tomcat-8.5.56-src.tar.gz"是Tomcat 8.5.56版本的源代码压缩包。 首先,让我们了解Tomcat的基本结构和组件。Tomcat的核心组件包括: 1. **Catalina**:这是Tomcat的主要部分,负责...

    java ant发布项目到tomcat

    6. **启动或重启Tomcat**: 可以使用Ant的`exec`任务运行Tomcat的`catalina.sh`或`catalina.bat`脚本来启动或重启服务器,确保新部署的应用生效。 7. **清理和构建顺序**: 在构建过程中,通常会有清理(clean)目标...

    apache-tomcat-8.5.38-src.zip

    这个压缩包"apache-tomcat-8.5.38-src.zip"包含了Apache Tomcat 8.5.38的源代码,让我们深入探讨一下其中蕴含的知识点。 **1. Apache Tomcat 8.x系列** Apache Tomcat 8.x是Tomcat服务器的一个主要版本,它支持Java...

    tomcat-7_API_帮助文档

    * tomcat-api.jar (Interfaces shared by Catalina and Jasper) * tomcat-coyote.jar (Tomcat connectors and utility classes) * tomcat-dbcp.jar (package renamed database connection pool based on Commons ...

    apache-tomcat-6.0.53-src

    在源码包`apache-tomcat-6.0.53-src`中,主要包含以下几个关键部分: 1. **Catalina**:这是Tomcat的核心模块,负责处理Servlet容器的主要任务,如加载Web应用、管理会话、处理请求和响应等。 2. **Covalent**:...

    apache-tomcat-9.0.12-src.tar.gz

    这个"apache-tomcat-9.0.12-src.tar.gz"压缩包包含了Tomcat 9.0.12版本的源代码,允许开发者深入理解其工作原理,并进行定制或扩展。 一、Tomcat基本概念 1. Servlet:Servlet是Java编程语言中的一个接口,用于扩展...

    Eclipse里配置Ant 组织的Project(3) -- E中配置Tomcat的JNDI

    配置完成后,我们需要将这个`context.xml`文件放在Tomcat的`conf/Catalina/localhost`目录下,或者在Eclipse的服务器视图中右键点击Tomcat服务器,选择“属性 -&gt; 部署”将`context.xml`添加到应用的部署描述符中。...

    apache-tomcat-6.0.45-src.zip

    Apache Tomcat是一款开源的Java ...总的来说,通过研究`apache-tomcat-6.0.45-src.zip`的源代码,开发者不仅可以提升对Java Web应用服务器的理解,还能获得解决实际问题的能力,为个人或团队的开发工作带来显著的效益。

    apache-tomcat-8.5.46-src.zip

    这个zip文件“apache-tomcat-8.5.46-src.zip”包含了Tomcat 8.5.46版本的源代码,是开发者深入理解、定制或调试Tomcat的基础。以下是关于Apache Tomcat 8.5.46源码的一些关键知识点: 1. **Tomcat版本**: 版本号...

    apache-tomcat-9.0.34-src.zip

    在本例中,我们讨论的是Apache Tomcat 9.0.34的源代码版本,即"apache-tomcat-9.0.34-src.zip"。这个压缩包包含了Tomcat服务器的全部源代码,对于开发者来说,这是一个宝贵的学习和调试资源,特别是对那些想要深入...

Global site tag (gtag.js) - Google Analytics