Ant编译(build.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!-- default="build" 意思是执行到build这一步 -->
<project name="dispatcher" basedir="." default="build">
	<!--Tomcat安装目录, 根据实际情况修改 -->
	<property name="tomcat.home" value="D:/apache-tomcat-6.0.35" />
	<!-- Tomcat工作目录 -->
	<property name="web.root" value="D:/webapps" />
	<!-- 项目名称 -->
	<property name="app.name" value="WebDispatcher" />
	<property name="src.dir" value="src" />
	<property name="classes.dir" value="WebContent/WEB-INF/classes" />
	<property name="lib.dir" value="WebContent/WEB-INF/lib" />

	<target name="clean" description="clean application">
		<echo message="----------delete application----------" />
		<delete dir="${web.root}/${app.name}" />
		<delete file="${web.root}/${app.name}.war" />
		<delete file="${app.name}.war" />
		<delete dir="${classes.dir}" />
	</target>


	<path id="classpath">
		<fileset dir="${lib.dir}" includes="**/*.jar" />
		<fileset dir="${lib.dir}" includes="**/*.zip" />
		<fileset dir="" includes="**/*.jar" />
		<fileset dir="${tomcat.home}/lib" includes="**/*.jar" />
	</path>
	<target name="compile" depends="clean" description="compile java files">
		<mkdir dir="${classes.dir}" />
		<javac encoding="utf-8" debug="true" fork="yes" listfiles="yes" memoryinitialsize="128m" memorymaximumsize="256m" srcdir="${src.dir}" destdir="${classes.dir}" includes="**/*.java" includeantruntime="build.sysclasspath=last">
			<classpath refid="classpath" />
		</javac>
		<copy todir="${classes.dir}">
			<fileset dir="${src.dir}" excludes="**/*.java">
			</fileset>
		</copy>
	</target>

	<!-- 记得前面的 default="build"么?对!就是这个build ,这些target通过depends关联起来,一步步顺序执行,应该很清楚,很明白吧 -->
	<target name="build" depends="compile" description="make war">
		<war destfile="../${app.name}.war" basedir="WebContent" webxml="WebContent/WEB-INF/web.xml">
			<classes dir="${classes.dir}" />
		</war>
	</target>



	<target name="deploy" depends="build" description="deploy project in tomcat">
		<echo message="----------deploy project----------" />
		<copy todir="${web.root}">
			<fileset dir="../">
				<include name="${app.name}.war" />
			</fileset>
		</copy>
	</target>

	<target name="desc" depends="deploy" description="unpack war">
		<echo message="----------unpack war----------" />
		<exec executable="jar" dir="${web.root}">
			<arg value="xvf" />
			<arg value="${app.name}.war" />
		</exec>
	</target>

	<target name="startup" depends="deploy" description="startup tomcat">
		<echo message="----------start tomcat----------" />
		<exec executable="cmd" dir="${tomcat.home}/bin">
			<arg value="/c" />
			<arg value="startup.bat" />
		</exec>
	</target>

	<target name="shutdown" description="shutdown tomcat">
		<echo message="----------close tomcat----------">
		</echo>
		<exec executable="cmd" dir="${tomcat.home}/bin">
			<arg value="/c" />
			<arg value="shutdown.bat" />
		</exec>
	</target>
</project>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值