设为首页 收藏本站
查看: 351|回复: 0

[经验分享] Catalina-Ant for Tomcat 7

[复制链接]

尚未签到

发表于 2017-1-17 10:16:42 | 显示全部楼层 |阅读模式
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.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-329664-1-1.html 上篇帖子: Tomcat部署web项目 下篇帖子: tomcat jboss weblogic
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表