Ant Learning Note (v) J2SE project based on unit testing, including compiling, testing, packaging, generating reports, uploading FTP

Source: Internet
Author: User
Tags ftp mkdir zip

This is just a description of ant build.xml files, other database connection files, please write your own


<?xml version= "1.0" encoding= "UTF-8"?> <project default= "ftp" > <property name= "src.dir" location= "src" ></property> <property name= "Test.src.dir" location= "test" ></property> <property name= " Lib.dir "location=" Lib "></property> <property file=" Build.properties "></property> < Property Name= "Build.dir" location= "Build" ></property> <property name= "build.classes" location= "${ Build.dir}/classes "></property> <property name=" Build.test.dir "location=" ${build.dir}/test "></ property> <property name= "build.test.classes" location= "${build.test.dir}/classes" ></property> < Property Name= "Build.test.report" location= "${build.test.dir}/report" ></property> <property name= " Build.jar.dir "location=" ${build.dir}/dist "></property> <property name=" Build.zip.dir "location=" ${ Build.dir}/zip "></property> <property name=" Build.doc.dir "location=" ${build.dir}/doc "></property> <property name=" build.src "location=" ${build.dir}/src "></property> < Property Name= "Metadata.dir" location= "metadata"/> <path id= "Compile-classpath" > <fileset dir= "${lib.dir } "includes=" *.jar "></fileset> </path> <path id=" Compile-test-classpath "> <path refid=" Compi Le-classpath "></path> <pathelement location=" ${build.classes} "/> </path> <path id=" run-test
	-classpath "> <path refid=" Compile-test-classpath "/> <pathelement location=" ${build.test.classes} "/> </path> <target name= "clean" > <delete dir= "${build.dir}"/> </target> <target name= "ini T "depends=" Clean,metadata "> <mkdir dir=" ${build.dir} "/> <mkdir dir=" ${build.classes} "/> <mkdir di R= "${build.test.dir}"/> <mkdir dir= "${build.test.classes}"/> <mkdir dir= "${build.test.report}"/> &lt ; mkdir dir= "${build.jar.dir}"/> &LT;mkdir dir= "${build.zip.dir}"/> <mkdir dir= "${build.doc.dir}"/> <mkdir dir= "${build.src}"/> <mkdi R dir= "${metadata.dir}"/> </target> <target name= "compile" depends= "init" > <javac destdir= "${build . Classes} "srcdir=" ${src.dir} "classpathref=" Compile-classpath "Includeantruntime=" true "failonerror=" true "> </javac> <copy todir= "${build.classes}" > <fileset dir= "${src.dir}" includes= "**/*.*" excludes= "**/*.J Ava ></fileset> </copy> </target> <target name= "compile-test" depends= "compile" > <ja Vac destdir= "${build.test.classes}" srcdir= "${test.src.dir}" Includeantruntime= "true" failonerror= "true" Clas spathref= "Compile-test-classpath" ></javac> </target> <target name= "Run-test" depends= " Compile-test "> <junit fork=" true "Haltonfailure=" false "failureproperty=" Junit.fail "> <classpath refid=" Run-test-classpath "></classpath> <formatter type= "brief" usefile= "false"/> <formatter type= "xml"/> <batchtest todir= "${build.test.repo RT} "> <fileset dir=" ${build.test.classes} "includes=" ${run.test.class} "></fileset> &LT;/BATCHTEST&G
		T </junit> <junitreport todir= "${build.test.report}" > <fileset dir= "${build.test.report}" includes= " Test*.xml "></fileset> <report format=" frames "todir=" ${build.test.report}/html "/> </junitreport&
		Gt <fail if= "${junit.fail}" message= "unit test failed, please check ${build.test.report}"/> </target> <target name= "Doc" depends= "Run-test" > <javadoc sourcepath= "${src.dir}" use= "true" packagenames= "cn.*" charset= "UTF-8" Encodin G= "UTF-8" docencoding= "UTF-8" destdir= "${build.doc.dir}" > <classpath refid= "Compile-classpath" ></clas spath> </javadoc> </target> <target name= "jar" depends= "Doc" > <tstamp> <format PR Operty= "Now" Pattern= "Yyyy-mm-dd HH:mm:ss"/> </tstamp> <jar destfile= "${build.jar.dir}/${project.jar.name}" basedir= "${
				build.classes} "duplicate=" preserve "> <manifest> <attribute name=" build-by "value=" ${user.name} "/> <attribute name= "Build-time" value= "${now}"/> </manifest> </jar> </target> <targe T name= "copy-src" depends= "jar" > <copy todir= "${build.src}" > <fileset dir= "${src.dir}" includes= "**/*.*" & gt;</fileset> </copy> </target> <target name= "metadata" > <mkdir dir= "${metadata.dir}"  /> <buildnumber/> <propertyfile file= "${metadata.dir}/build.propterties" > <entry key= "Build-time" Type= "Date" value= "Now" pattern= "Yyyy-mm-dd HH:mm:ss"/> <entry key= "build-number" type= "int" value= "${build.num ber} "/> </propertyfile> </target> <target name=" Zip "depends=" copy-src "> <zip destfile=" ${ Build.zip.dir}/${project.Zip.name} "duplicate=" preserve "> <zipfileset file=" ${build.jar.dir}/${project.jar.name} "prefix=" ${ Project.prefix} "/> <zipfileset dir=" ${build.src} "includes=" **/*.* "prefix=" ${PROJECT.PREFIX}/SRC "></ zipfileset> <zipfileset dir= "${build.doc.dir}" includes= "**/*.*" prefix= "${project.prefix}/doc/api" ></ zipfileset> <zipfileset dir= "${build.test.dir}" includes= "**/*.*" excludes= "Report/*.*" prefix= "${PROJECT.P Refix}/test "></zipfileset> <zipfileset dir=". "Includes=" build.xml,build.properties "prefix=" ${ Project.prefix} "></zipfileset> </zip> </target> <!--equivalent to the use of functions--<presetdef name=" Uplo Ad "> <ftp userid=" ${ftp.username} "password=" ${ftp.password} "server=" ${ftp.server} "remotedir=" ${ftp.dir} "&G  t;</ftp> </presetdef> <target name= "ftp" depends= "Zip" > <!--here upload functions are used---<upload action= "mkdir"/> <upload action= "put" > <filESET dir= "${build.zip.dir}" includes= "${project.zip.name}" ></fileset> </upload> </target> < /project>

Build.properties

Ftp.username = Ant
ftp.password = ant
ftp.server = localhost
ftp.dir = user_manager
project.version = SNAPSHOT-0.1
project.prefix = usermanager-${project.version}
project.jar.name = ${project.prefix}.jar
Project.zip.name = ${project.prefix}.zip
Run.test.class = **/test*.class


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.