远程部署tomcat

 
背景:
 
客户端:xp(192.168.1.102) +eclipse自带的ant
服务器:linux(192.168.1.100) +tomcat6
通过客户端的ant远程部署项目到linux服务器
 
Step1) 配置客户端
将服务端的${CATALINA_HOME}/lib/catalina-ant.jar拷贝到客户端的${ANT_HOME}/lib
客户端的${ANT_HOME}在本文中指的是D:/dev/eclipse/plugins/org.apache.ant_1.6.5/lib
即eclipse自带的ant目录,为了让eclipse自带的ant能正常运行任务,你还得将这个jar添加到eclipse的ant的classpath中(windows-->preferences-->Ant-->runtime-->classpath)
 
你完全可以不使用eclipse自带的ant,上面的步骤显得很麻烦,你完全可以开启dos窗口运行ant,但这样的话你就的两边切换窗口,一边在eclipse下写代码,一边在dos下运行ant,根据的自己的实际情况取舍吧
 
Step2) 配置服务器
我们主要通过tomcat manager api来完成部署工作,这个需要权限,所以你的修改
$CATALINA_HOME/conf/tomcat-users.xml加入
 
< user name = " craigmcc "  password = " secret "  roles = " manager "   />
 
你可以通过手动访问下面的地址
 
如果成功,说明你的服务端配置正确
 
Step3)客户端脚本
< project name = " My Application "   default = " war "  basedir = " . " >
 
<!--  Configure the directory into which the web application  is  built  -->
< property name = " build "  value = " ${basedir}/webcontent/WEB-INF/classes "   />
< property name = " dist.dir "  value = " ${basedir}/dist "   />
 
<!--  Configure the context path  for   this  application  -->
< property name = " path "  value = " /search "   />
 
<!--  Configure properties to access the Manager application  -->
< property name = " url "  value = " http://192.168.1.100/manager "   />
< property name = " username "  value = " weip "   />
< property name = " password "  value = " 123 "   />
 
<!--  Configure the custom Ant tasks  for  the Manager application  -->
< taskdef name = " deploy "  classname = " org.apache.catalina.ant.DeployTask "   />
< taskdef name = " undeploy "  classname = " org.apache.catalina.ant.UndeployTask "   />
 
<!--  Executable Targets  -->
。。。。。。。。。。。。。。。。。。。。
< target name = " war "  description = " package web application " >
< war destfile = " ${dist.dir}/search.war "  webxml = " webcontent/WEB-INF/web.xml " >
     
< classes dir = " webcontent/WEB-INF/classes "   />
     
< fileset dir = " webcontent "  excludes = " WEB-INF/** "   />
 
< lib dir = " webcontent/WEB-INF/lib "   />
</ war >
</ target >
 
< target name = " deploy "  description = " Install web application "  depends = " war " >
< deploy url = " ${url} "  username = " ${username} "  password = " ${password} "  path = " ${path} "  war = " ${dist.dir}/search.war "   />
</ target >
 
 
< target name = " undeploy "  description = " Remove web application " >
< undeploy url = " ${url} "  username = " ${username} "  password = " ${password} "  path = " ${path} "   />
</ target >
 
</ project >
 
开始运行
 
 
第一次部署
结果:
2007 - 7 - 30   22 : 35 : 59  org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive search.war
2007 - 07 - 30   22 : 36 : 03 , 595  INFO XmlConfigurationProvider  -  Parsing configuration file [struts - default .xml]
2007 - 07 - 30   22 : 36 : 03 , 887  INFO XmlConfigurationProvider  -  Parsing configuration file [struts - plugin.xml]
2007 - 07 - 30   22 : 36 : 03 , 923  INFO XmlConfigurationProvider  -  Parsing configuration file [struts.xml]
2007 - 07 - 30   22 : 36 : 04 , 140  INFO ObjectTypeDeterminerFactory  -  Detected GenericsObjectTypeDeterminer, initializing it...
2007 - 07 - 30   22 : 36 : 04 , 146  INFO XWorkConverter  -  Detected AnnotationXWorkConverter, initializing it...
 
成功
 
第二次部署出现错误:
deploy:
   [deploy] FAIL 
-  Application already exists at path  /search
 
于是将
< target name = " deploy "  description = " Install web application "  depends = " war " >
。。。。。。。。
</ target >
变为
< target name = " deploy "  description = " Install web application "  depends = " war,undeploy " >
。。。。。。。。
</ target >
 
结果:
信息: Undeploying context [ / search]
2007 - 7 - 30   22 : 46 : 27  org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive search.war
2007 - 07 - 30   22 : 46 : 29 , 926  INFO XmlConfigurationProvider  -  Parsing configuration file [struts - default .xml]
2007 - 07 - 30   22 : 46 : 30 , 048  INFO XmlConfigurationProvider  -  Parsing configuration file [struts - plugin.xml]
2007 - 07 - 30   22 : 46 : 30 , 083  INFO XmlConfigurationProvider  -  Parsing configuration file [struts.xml]
2007 - 07 - 30   22 : 46 : 30 , 250  INFO ObjectTypeDeterminerFactory  -  Detected GenericsObjectTypeDeterminer, initializing it...
2007 - 07 - 30   22 : 46 : 30 , 252  INFO XWorkConverter  -  Detected AnnotationXWorkConverter, initializing it...
 
成功
 
总结:
本文主要通过ant脚本来远程部署tomcat,旨在做一个尝试,上面的脚本与这种部署方式都与实际的环境相差甚远,这种部署方式适合服务器和客户端没有程序配置差别的应用,一旦有了程序配置差别,这种方式就不合适了,你可以考虑采用在服务器段进行本地部署消除这种差别(对于复杂的部署环境也许是两者的结合),这样也有利于持续构建。
 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值