ANT工程配置

终于把ANT搞定了,现在发布一个通用的ANT的build.xml文件,以备后用。


<project name="hnwt114" default="build" basedir=".">
	<!-- 工程根目录 -->
	<property name="hnwt144.home" value="."/>
	<!-- 工程根名 -->
	<property name="hnwt144.name" value="HNWT114"/>
	<!-- tomcat路径 -->
	<property name="tomcat.home" value="D:\apache-tomcat-5.5.26"/>
	<!-- tomcat部署路径 -->
	<property name="webapps.home" value="${tomcat.home}/webapps"/>
	<!-- JAVA源文件路径 -->
	<property name="src.home" value="${hnwt144.home}/src"/>
	
	<!-- class文件存放位置 -->
	<property name="classes.home" value="${hnwt144.home}/classes"/>
	<!-- 发布文件夹 -->
	<property name="deploy.home" value="${hnwt144.home}/deploy"/>
	<!-- webRoot路径 -->
	<property name="web.home" value="${hnwt144.home}/webRoot"/>
	
	<!-- 创建工程路径 -->
	<property name="build.home" value="${hnwt144.home}/build"/>
	<!-- /WEB-INF/classes -->
	<property name="build.classes" value="${hnwt144.home}/WEB-INF/classes"/>
	<!-- /WEB-INF/lib -->
	<property name="build.lib" value="${hnwt144.home}/WEB-INF/lib"/>
	<!-- 工程引用包 -->
	<property name="lib.home" value="${web.home}/WEB-INF/lib"/>
	
	
	<!-- 编译工程所需的JAR包 -->
	<path id="compile.classpath">
		<pathelement location="${classes.home}"/>
		<fileset dir="${lib.home}">
				<include name="*.jar"/>
				<include name="*.zip"/>
		</fileset>
		<fileset dir="${tomcat.home}/common/lib">
			<include name="*.jar"/>
		</fileset>
		<pathelement location="${tomcat.home}/common/classes"/>
	</path>
	
	
	<!-- 测试ANT -->
	<target name="help">
		<echo message="Please specify a target![usage:ant&lt;targetname&gt;]"/>
		<echo message="Here is a list of possible targets:"/>
		<echo message="  clean-all....Delete build dir,all .class and war files"/>
		<echo message="  perpare....Creates directories if requied"/>
		<echo message="  compile....Compiles source files"/>
		<echo message="  build......Build war file from.class and other files"/>
		<echo message="  deploy......Copy war file to the webapps directory"/>
	</target>
	
	
	<!-- 清除 -->
	<target name="clean-all">
		<delete dir="${build.home}"/>
		<delete dir="${classes.home}"/>
		<delete dir="${deploy.home}"/>
		
		<delete dir="${webapps.home}/${hnwt114.home}" failonerror="false"/>
		<delete dir="${webapps.home}/${hnwt114.name}.war"/>
	</target>
	
	
	<!-- 准备工作 -->
	<target name="prepare">
		<echo message="Tomcat Home=${tomcat.home}"/>
		<echo message="Webapps Home=${webapps.home}"/>
		
		<mkdir dir="${classes.home}"/>
		<mkdir dir="${deploy.home}"/>		
		
		<mkdir dir="${build.home}"/>
		<mkdir dir="${build.home}/WEB-INF"/>
		<mkdir dir="${build.home}/WEB-INF/classes"/>
		<mkdir dir="${build.home}/WEB-INF/lib"/>
	</target>
	
	
	<!-- 编译 -->
	<target name="compile" depends="prepare">
		<javac srcdir="${src.home}" destdir="${classes.home}" debug="no">
			<classpath refid="compile.classpath"/>
		</javac>
	</target>
	
	<!-- 构建临时工程 -->
	<target name="build" depends="compile">
		<copy todir="${build.home}">
			<fileset dir="${web.home}"/>
		</copy>
		<copy todir="${build.home}/WEB-INF/classes">
			<fileset dir="${classes.home}"/>
		</copy>
		
		<copy todir="${build.home}/WEB-INF/classes">
			<fileset dir="${src.home}">
				<include name="**/*.properties"/>
				<include name="**/*.prop"/>
			</fileset>
		</copy>
		
		<jar jarfile="${deploy.home}/${hnwt144.name}.war" basedir="${build.home}"/>
	</target>
	<!-- 发布 -->
	<target name="deploy" depends="build">
		<copy todir="${webapps.home}" file="${deploy.home}/${hnwt144.name}.war"/>
	</target>
		
	</project>

你可能感兴趣的:(eclipse,tomcat,MyEclipse,qq,ant)