Ant远程部署Tomcat

客户端:xp(192.168.1.102) +eclipse自带的ant
服务器:linux(192.168.1.100) +tomcat6
通过客户端的ant远程部署项目到linux服务器
 
1) 配置客户端
将服务端的${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,根据的自己的实际情况取舍吧
 
2) 配置服务器
我们主要通过tomcat manager api来完成部署工作,这个需要权限,所以你的修改
$CATALINA_HOME/conf/tomcat-users.xml加入
<user name="ant" password="secret" roles="manager" />
 
你可以通过手动访问下面的地址
http://192.168.1.100/manager/html

如果成功,说明你的服务端配置正确

3)build.properties
project.war = test.war
project.jar = webapp.jar
build.dir = dist
servlet.dir = ../ant/src
compile.dir = WebContent/WEB-INF/lib
classes.dir = WebContent/WEB-INF/classes
web.path = chouwo

4)build.xml

<?xml version="1.0" encoding="utf-8"?>
<project name="Web App" default="dist" basedir=".">
	<property file="build.properties" />
	
	<path id="project.lib">
		<fileset dir="${compile.dir}">
			<include name="*.jar" />
		</fileset>
		<fileset dir="${servlet.dir}">
			<include name="*.jar" />
		</fileset>
	</path>

	<target name="clean">
		<delete dir="${build.dir}" />
		<delete dir="${classes.dir}" />
	</target>

	<target name="compile" depends="clean">
		<mkdir dir="${classes.dir}" />
		<javac encoding="UTF-8" classpath="." destdir="${classes.dir}" includeantruntime="false">
			<classpath refid="project.lib" />
			<src path="src" />
		</javac>
		<copy todir="${classes.dir}">
			<fileset dir="config" />
		</copy>
	</target>

	<target name="jar" depends="compile">
		<jar encoding="UTF-8" destfile="${build.dir}/${project.jar}"  basedir="${classes.dir}" includes="**"/>
		<delete dir="${classes.dir}" />
	</target>
	
	<target name="war" depends="jar">
		<war encoding="UTF-8" destfile="${build.dir}/${project.war}" webxml="WebContent/WEB-INF/web.xml">
			<fileset dir="WebContent" />
			<lib file="${build.dir}/${project.jar}" />
		</war>
		<delete file="${build.dir}/${project.jar}" />
	</target>

	<property name="path" value="/${web.path}" />
	<property name="url" value="http://192.168.1.100/manager" />
	<property name="username" value="ant" />
	<property name="password" value="secret" />
	
	<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
	<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />
	
	<target name="deploy" depends="war">
		<deploy url="${url}" username="${username}" password="${password}" path="${path}" 
			war="${build.dir}/${project.war}" />
	</target>

	<target name="undeploy">
		<undeploy url="${url}" username="${username}" password="${password}" path="${path}" />
	</target>
	
	<target name="dist" depends="compile,jar,war" />
</project>


你可能感兴趣的:(Ant远程部署)