Ant学习笔记1

以前一直都用eclipse进行项目构建、编译、测试、部署,所有的一切都依赖于IDE。如果离开IDE(比如需要在某台linux机器上进行开发,没有GUI界面),则想调试将比较难(因为本地有时无法模拟生产机器的环境),于是最近利用空余时间看了下Ant构建方面的资料,整出如下build.xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== 
     2011-6-23 下午05:23:55                                               
     chenza                                                                
     ====================================================================== -->
<project name="monkey-build" default="package" basedir=".">
	<property name="src.dir" location="src"/>
	<property name="src.main.dir" location="${src.dir}/main"/>
	<property name="src.test.dir" location="${src.dir}/test"/>	
	<property name="build.dir" location="build"/>
	<property name="build.main.dir" location="${build.dir}/main"/>
	<property name="build.test.dir" location="${build.dir}/test"/>	
	<property name="lib.dir" location="lib"/>
	<property name="dist.dir" location="dist"/>
	<property name="bin.dir" location="bin"/>
	<property name="test.data.dir" location="${build.dir}/data"/>
	<property name="test.report.dir" location="${build.dir}/report"/>
	<property name="test.suite" value="com.monkey.util.HelloMonkeyTest"/>
	<property name="svn.remote.url" value="http://mushroom-monkey.googlecode.com/svn/mushroom/"/>
	
	<path id="path.svnant">
		<pathelement location="${lib.dir}/svnjavahl.jar"/>
      	<pathelement location="${lib.dir}/svnant.jar"/>
		<pathelement location="${lib.dir}/svnClientAdapter.jar"/>
		<pathelement location="${lib.dir}/ganymed.jar"/>
		<pathelement location="${lib.dir}/jna.jar"/>		
		<pathelement location="${lib.dir}/svnkit.jar"/>
      	<!-- 
		 -->
  	</path>

  	<typedef 
      	resource="org/tigris/subversion/svnant/svnantlib.xml" 
      	classpathref="path.svnant"
  	/>
	
    <target name="init">
    	<tstamp/>
    	<mkdir dir="${src.main.dir}"/>
    	<mkdir dir="${src.test.dir}"/>
    	<mkdir dir="${build.main.dir}"/>
    	<mkdir dir="${build.test.dir}"/>
    	<mkdir dir="${test.data.dir}"/>
    	<mkdir dir="${test.report.dir}"/>
    	<mkdir dir="${lib.dir}"/>
    	<mkdir dir="${dist.dir}"/>   	
    	<mkdir dir="logs"/>
    	<mkdir dir="conf/spring"/>
    </target>
	
	<path id="project.classpath">
		<fileset dir="${lib.dir}" id="lib_dir">
		    <include name="**/*.jar"/>
		</fileset>
	</path>
	
	<path id="build.main.path">
		<pathelement location="${build.main.dir}"/>
		<pathelement location="${build.test.dir}"/>
	</path>
	
	<target name="compile.main" depends="init">
		<javac encoding="UTF-8" srcdir="${src.main.dir}" destdir="${build.main.dir}" debug="true" 
			includeantruntime="true" includejavaruntime="true">
			<classpath refid="project.classpath"/>
		</javac>		
	</target>
	
	<target name="compile.test" depends="compile.main">
		<javac encoding="UTF-8" srcdir="${src.test.dir}" destdir="${build.test.dir}" debug="true"
			includeantruntime="true" includejavaruntime="true">
			<classpath refid="project.classpath"/>
			<classpath refid="build.main.path"/>
		</javac>		
	</target>
	
	<target name="package" depends="compile.main">
		<delete file="${dist.dir}/monkey-sdk.jar"></delete>
		<pathconvert property="mf.classpath" pathsep=" ">
			<path refid="project.classpath" />
			<globmapper from="${lib.dir}*.jar" to="lib*.jar" />
		</pathconvert>
		<jar destfile="${dist.dir}/monkey-sdk.jar" 
			 basedir="${build.main.dir}"
			 includes="com/**">
			<manifest>
				<attribute name="Main-Class" value="com.monkey.util.HelloMonkey"/>
				<attribute name="Class-Path" value="${mf.classpath}"/>
			</manifest>	
		</jar>
	</target>
	
	<target name="package.src">
		<delete file="${dist.dir}/monkey-sdk-src.jar"></delete>
		<jar destfile="${dist.dir}/monkey-sdk-src.jar" 
			 basedir="${src.dir}"/>
	</target>
	
	<target name="ipconfig">
		<exec executable="ipconfig">
		</exec>
	</target>
	
	<target name="test-basic" depends="compile.test">	<!-- printsummary="withOutAndErr" -->
		<junit haltonfailure="true" printsummary="false"><!-- build process halt when test fail  -->
			<classpath refid="project.classpath"/>
			<classpath refid="build.main.path"/>
			<formatter type="brief" usefile="false"/>
			<formatter type="xml"/>
			<!--
			<test name="${test.suite}"/>
			-->
			<batchtest todir="${test.data.dir}">
				<fileset dir="${build.test.dir}"
					includes="**/*Test.class" />		
			</batchtest>
		</junit>
		<junitreport todir="${test.data.dir}">
			<fileset dir="${test.data.dir}">
				<include name="TEST-*.xml"/>
			</fileset>
			<report format="frames" todir="${test.report.dir}"/>
		</junitreport>
	</target>
	
	<target name="test-report" depends="compile.test">
		<junit printsummary="false" failureproperty="test.fail" errorproperty="test.fail">
			<classpath refid="project.classpath"/>
			<classpath refid="build.main.path"/>
			<formatter type="brief" usefile="false"/>
			<formatter type="xml"/>
			<batchtest todir="${test.data.dir}">
				<fileset dir="${build.test.dir}"
					includes="**/*Test.class" />		
			</batchtest>
		</junit>
		<junitreport todir="${test.data.dir}">
			<fileset dir="${test.data.dir}">
				<include name="TEST-*.xml"/>
			</fileset>
			<report format="frames" todir="${test.report.dir}"/>
		</junitreport>
		<fail if="test.fail">
			Tests failed. Check  ${test.report.dir}
		</fail>
		
	</target>
	
	<target name="clean">
		<delete dir="${build.dir}"/>
	</target>
	
	<target name="update">
        <svn javahl="true" username="cza55007@gmail.com" password="*********">
            
        	<checkout url="${svn.remote.url}" revision="HEAD" destpath="${build.dir}" />   
        </svn>
    </target>
	
</project>


 

 

且当做笔记,同时也供有此困惑的朋友们参考,如有问题,请批评指正。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值