ant build.xml

本文详细介绍了使用Ant构建工具进行Web应用项目的构建过程。从配置文件的结构开始,逐步解析了如何设置项目路径、编译源代码、清理构建目录、打包成WAR文件,并最终部署到Tomcat服务器上。
<?xml version="1.0" encoding="UTF-8"?>
<project name="foo" basedir="../" default="clean">

	
	<property name="TOMCAT_HOME" value="C:/Users/XXX/server/apache-tomcat-6.0.37-8081" />
	<property name="APP_NAME" value="foo" />

	<property name="web.content" value="WebContent" />
	<property name="WEBCONTENT" location="WebContent" />
	<property name="WEBINF" location="${WEBCONTENT}/WEB-INF" />
	<property name="CLASSES" location="${WEBINF}/classes" />
	<property name="LIBS" location="${WEBINF}/lib" />
	<property name="LIBS_TO_COMPILE" location="lib" />
	<property name="OTHER_LIBS_TO_COMPILE" location="lib_other" />
	<property name="DIST" location="dist" />
	<property name="SRC" location="src" />

	<path id="build.class.path">
		<fileset dir="${LIBS}">
			<include name="**/*.jar" />
		</fileset>
		<fileset dir="${LIBS_TO_COMPILE}">
			<include name="**/*.jar" />
		</fileset>
		<fileset dir="${OTHER_LIBS_TO_COMPILE}">
			<include name="**/*.jar" />
		</fileset>
	</path>


	<target name="clean">
		<delete dir="${DIST}" />
		<delete dir="${CLASSES}" />
		<mkdir dir="${DIST}" />
		<mkdir dir="${CLASSES}" />
		<!--
		<delete>
			<fileset dir="${CLASSES}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
				<include name="**/*.list" />
				<include name="**/*.MD5" />
				<include name="**/*.class" />
			</fileset>
		</delete>
		-->
	</target>

	<target name="compile" depends="clean">
		<javac srcdir="${SRC}" destdir="${CLASSES}" includeantruntime="false" compiler="javac1.6" nowarn="true" fork="true" memoryinitialsize="128m" memorymaximumsize="512m" debug="false" debuglevel="lines,var,source" verbose="false">
			<classpath>
				<path refid="build.class.path" />
			</classpath>
		</javac>
		<!-- <antcall target="copyFilesToClasspath" /> -->
	</target>

	<!-- - - - - - - - - - - - - - - - - - 
          target: copyFilesToClasspath                      
         - - - - - - - - - - - - - - - - - 
	<target name="copyFilesToClasspath">
		<copy todir="${CLASSES}">
			<fileset dir="${RESOURCES}" />
			<fileset dir="${SRC}">
				<exclude name="**/*.java" />
			</fileset>
		</copy>
	</target>

	<target name="loadSVNInfo">
		<loadfile property="svn.revision" srcFile=".svn/entries" failonerror="true">
			<filterchain>
				<headfilter lines="1" skip="3" />
				<deletecharacters chars="\n" />
			</filterchain>
		</loadfile>
		<loadfile property="svn.url" srcFile=".svn/entries" failonerror="true">
			<filterchain>
				<headfilter lines="1" skip="4" />
				<deletecharacters chars="\n" />
			</filterchain>
		</loadfile>
		<loadfile property="svn.lastcommit" srcFile=".svn/entries" failonerror="true">
			<filterchain>
				<headfilter lines="1" skip="9" />
				<deletecharacters chars="\n" />
			</filterchain>
		</loadfile>
		<tstamp>
			<format property="package.build.time" pattern="dd-MMMM-yyyy hh:mm:ss" locale="en,US" />
		</tstamp>
	</target>
-->
	<target name="war" depends="compile">
		<war destfile="${DIST}/${APP_NAME}.war" update="false">
			<fileset dir="${WEBCONTENT}">
				<include name="**/*" />
			</fileset>
			<!--
			<manifest>
				<attribute name="Package-BuildTime" value="${package.build.time}" />
				<attribute name="SVN-Revision" value="${svn.revision}" />
				<attribute name="SVN-URL" value="${svn.url}" />
				<attribute name="SVN-Checkout-User" value="${svn.checkout.user}" />
				<attribute name="SVN-LastCommit-Time" value="${svn.lastcommit}" />
			</manifest>
			-->
		</war>
	</target>
<!--
	<target name="server-war" depends="war">
	</target>

	<target name="all" depends="war" description="compiles and packs webapp">
	</target>
-->
	<target name="publish" depends="war" description="copy war to tomcat">
		<copy todir="${TOMCAT_HOME}/webapps">
			<fileset dir="${DIST}">
				<include name="${APP_NAME}.war" />
			</fileset>
		</copy>
	</target>
</project>



转载于:https://my.oschina.net/u/1015065/blog/178018

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值