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}" failοnerrοr="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}" failοnerrοr="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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值