背景:
客户端: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加入
<
username
=
"
craigmcc
"
password
=
"
secret
"
roles
=
"
manager
"
/>
你可以通过手动访问下面的地址
如果成功,说明你的服务端配置正确
Step3)客户端脚本
<
projectname
=
"
MyApplication
"
default
=
"
war
"
basedir
=
"
.
"
>

<!--
Configurethedirectoryintowhichthewebapplication
is
built
-->
<
propertyname
=
"
build
"
value
=
"
${basedir}/webcontent/WEB-INF/classes
"
/>
<
propertyname
=
"
dist.dir
"
value
=
"
${basedir}/dist
"
/>

<!--
Configurethecontextpath
for
this
application
-->
<
propertyname
=
"
path
"
value
=
"
/search
"
/>

<!--
ConfigurepropertiestoaccesstheManagerapplication
-->
<
propertyname
=
"
url
"
value
=
"
http://192.168.1.100/manager
"
/>
<
propertyname
=
"
username
"
value
=
"
weip
"
/>
<
propertyname
=
"
password
"
value
=
"
123
"
/>

<!--
ConfigurethecustomAnttasks
for
theManagerapplication
-->
<
taskdefname
=
"
deploy
"
classname
=
"
org.apache.catalina.ant.DeployTask
"
/>
<
taskdefname
=
"
undeploy
"
classname
=
"
org.apache.catalina.ant.UndeployTask
"
/>

<!--
ExecutableTargets
-->
。。。。。。。。。。。。。。。。。。。。
<
targetname
=
"
war
"
description
=
"
packagewebapplication
"
>
<
wardestfile
=
"
${dist.dir}/search.war
"
webxml
=
"
webcontent/WEB-INF/web.xml
"
>
<
classesdir
=
"
webcontent/WEB-INF/classes
"
/>
<
filesetdir
=
"
webcontent
"
excludes
=
"
WEB-INF/**
"
/>
<
libdir
=
"
webcontent/WEB-INF/lib
"
/>
</
war
>
</
target
>

<
targetname
=
"
deploy
"
description
=
"
Installwebapplication
"
depends
=
"
war
"
>
<
deployurl
=
"
${url}
"
username
=
"
${username}
"
password
=
"
${password}
"
path
=
"
${path}
"
war
=
"
${dist.dir}/search.war
"
/>
</
target
>


<
targetname
=
"
undeploy
"
description
=
"
Removewebapplication
"
>
<
undeployurl
=
"
${url}
"
username
=
"
${username}
"
password
=
"
${password}
"
path
=
"
${path}
"
/>
</
target
>

</
project
>
开始运行
第一次部署
结果:
2007
-
7
-
30
22
:
35
:
59
org.apache.catalina.startup.HostConfigdeployWAR
信息:Deployingwebapplicationarchivesearch.war
2007
-
07
-
30
22
:
36
:
03
,
595
INFOXmlConfigurationProvider
-
Parsingconfigurationfile[struts
-
default
.xml]
2007
-
07
-
30
22
:
36
:
03
,
887
INFOXmlConfigurationProvider
-
Parsingconfigurationfile[struts
-
plugin.xml]
2007
-
07
-
30
22
:
36
:
03
,
923
INFOXmlConfigurationProvider
-
Parsingconfigurationfile[struts.xml]
2007
-
07
-
30
22
:
36
:
04
,
140
INFOObjectTypeDeterminerFactory
-
DetectedGenericsObjectTypeDeterminer,initializingit...
2007
-
07
-
30
22
:
36
:
04
,
146
INFOXWorkConverter
-
DetectedAnnotationXWorkConverter,initializingit...
第二次部署出现错误:
deploy:
[deploy]FAIL
-
Applicationalreadyexistsatpath
/search
于是将
<
targetname
=
"
deploy
"
description
=
"
Installwebapplication
"
depends
=
"
war
"
>
。。。。。。。。
</
target
>
变为
<
targetname
=
"
deploy
"
description
=
"
Installwebapplication
"
depends
=
"
war,undeploy
"
>
。。。。。。。。
</
target
>
结果:
信息:Undeployingcontext[
/
search]
2007
-
7
-
30
22
:
46
:
27
org.apache.catalina.startup.HostConfigdeployWAR
信息:Deployingwebapplicationarchivesearch.war
2007
-
07
-
30
22
:
46
:
29
,
926
INFOXmlConfigurationProvider
-
Parsingconfigurationfile[struts
-
default
.xml]
2007
-
07
-
30
22
:
46
:
30
,
048
INFOXmlConfigurationProvider
-
Parsingconfigurationfile[struts
-
plugin.xml]
2007
-
07
-
30
22
:
46
:
30
,
083
INFOXmlConfigurationProvider
-
Parsingconfigurationfile[struts.xml]
2007
-
07
-
30
22
:
46
:
30
,
250
INFOObjectTypeDeterminerFactory
-
DetectedGenericsObjectTypeDeterminer,initializingit...
2007
-
07
-
30
22
:
46
:
30
,
252
INFOXWorkConverter
-
DetectedAnnotationXWorkConverter,initializingit...
成功
总结:
本文主要通过ant脚本来远程部署tomcat,旨在做一个尝试,上面的脚本与这种部署方式都与实际的环境相差甚远,这种部署方式适合服务器和客户端没有程序配置差别的应用,一旦有了程序配置差别,这种方式就不合适了,你可以考虑采用在服务器段进行本地部署消除这种差别(对于复杂的部署环境也许是两者的结合),这样也有利于持续构建。
256

被折叠的 条评论
为什么被折叠?



