Ant
At this place,I just want to say ant isn't so hard to study.
start to study the build.xml
<!--project name is testSpring now we buid the war-->
<project name="testSpring" default="war" basedir=".">
<!--the environment of system,we will use it after-->
<property environment="env"></property>
<property name="src.dir" location="src"></property>
<!--src ,test,conf,webcontent at the same folder-->
<property name="test.src.dir" location="test"></property>
<property name="conf.dir" location="conf"></property>
<property name="web.dir" location="WebContent"></property>
<property name="lib.dir" location="${web.dir}/WEB-INF/lib"></property>
<!--compile class in the bin folder-->
<property name="build.dir" location="bin"></property>
<property name="build.classes" location="${build.dir}/classes"></property>
<property name="build.test.dir" location="${build.dir}/test"></property>
<!--test class folder-->
<property name="build.test.classes" location="${build.test.dir}/classes"></property>
<!--test report-->
<property name="build.test.report" location="${build.test.dir}/report"></property>
<property name="build.doc.dir" location="${build.dir}/doc"></property>
<!--where is war-->
<property name="build.war.dir" location="${build.dir}/war"></property>
<property name="test.lib.dir" location="lib"></property>
<path id="compile-classpath">
<!--import the jar in the lib-->
<fileset dir="${lib.dir}" includes="*.jar"></fileset>
<!--import jar in the tomcat .remember to config the tomcat in path -->
<fileset dir="${env.CATALINA_HOME}/lib" includes="*.jar"></fileset>
<!--import jar in test -->
<fileset dir="${test.lib.dir}" includes="*.jar"></fileset>
</path>
<!--Now,we begin compile-->
<path id="compile-test-classpath">
<!--include the jar-->
<path refid="compile-classpath"></path>
<!--where we can find compiled class -->
<pathelement location="${build.classes}"/>
</path>
<path id="run-test-classpath">
<!--include the jar-->
<path refid="compile-test-classpath"/>
<!--where we can find compiled test class-->
<pathelement location="${build.test.classes}"/>
</path>
<target name="clean">
<!--when we start build,we need to clean the path-- >
<delete dir="${build.dir}"/>
</target>
<!--If the clean target happen error,the target of init don't run-->
<target name="init" depends="clean">
<!--build the path-->
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.test.dir}"/>
<mkdir dir="${build.test.classes}"/>
<mkdir dir="${build.test.report}"/>
<mkdir dir="${build.doc.dir}"/>
<mkdir dir="${build.war.dir}"/>
<mkdir dir="${build.war.dir}/WEB-INF"/>
<mkdir dir="${build.war.dir}/WEB-INF/class"/>
</target>
<target name="compile" depends="init">
<!-- compile the java from src to build include the information when it is compiled-->
<javac destdir="${build.classes}" srcdir="${src.dir}"
classpathref="compile-classpath"
includeantruntime="true" failonerror="true" debug="true" encoding="utf-8"></javac>
<!--move the file in src except .java-->
<copy todir="${build.classes}">
<fileset dir="${src.dir}" includes="**/*.*" excludes="**/*.java"></fileset>
</copy>
<!--move the file in conf except .java-->
<copy todir="${build.classes}">
<fileset dir="${conf.dir}"></fileset>
</copy>
</target>
<!-- compile the java from test to build include the information when it is compiled-->
<target name="compile-test" depends="compile">
<javac destdir="${build.test.classes}" srcdir="${test.src.dir}"
includeantruntime="true" failonerror="true"
classpathref="compile-test-classpath" encoding="utf-8"></javac>
</target>
<!-run test-->
<!--you can find format on the Internet-->
<target name="run-test" depends="compile-test">
<junit fork="true" haltonfailure="false" failureproperty="junit.fail" >
<!--classpath-->
<classpath location="${build.classes}" />
<classpath location="${build.test.classes}" />
<classpath refid="compile-classpath"></classpath>
<formatter type="xml" />
<test name="${testcase}" todir="${reports.xml.dir}" if="testcase" />
<batchtest todir="${build.test.report}" unless="testcase">
<fileset dir="${test.src.dir}" includes="**/*Test.java" ></fileset>
</batchtest>
</junit>
<junitreport>
<fileset dir="${build.test.report}" includes="TEST-*.xml"></fileset>
<report format="frames" todir="${build.test.report}/html"/>
</junitreport>
<fail if="${junit.fail}" message="单元测试失败,具体情况请查询${build.test.report}"/>
</target>
<!--after test and compile ,If successful,you can find a document in build.doc.dir-->
<target name="doc" depends="run-test">
<echo>${env}</echo>
<javadoc sourcepath="${src.dir}" use="true" packagenames="com.*"
charset="UTF-8" encoding="UTF-8" docencoding="UTF-8"
destdir="${build.doc.dir}">
<classpath refid="compile-classpath"></classpath>
</javadoc>
</target>
<!--It's begin to build war-->
<target name="unWar" depends="compile-test">
<!--just copy-->
<copy todir="${build.war.dir}">
<fileset dir="${web.dir}"></fileset>
</copy>
<!--just copy-->
<copy todir="${build.war.dir}/WEB-INF/class">
<fileset dir="${build.classes}">
</fileset>
</copy>
</target>
<target name="war" depends="unWar">
<delete file="${build.dir}/${ant.project.name}.war"></delete>
<war destfile="${build.dir}/${ant.project.name}.war" webxml="${build.war.dir}/WEB-INF/web.xml">
<fileset dir="${build.war.dir}" />
</war>
</target>
<!--you will use the env.CATALINA_HOME at this-->
<target name="deploy" depends="war">
<exec executable="${env.CATALINA_HOME}/bin/shutdown.bat"/>
<delete file="${env.CATALINA_HOME}/webapps/${ant.project.name}.war"></delete>
<delete dir="${env.CATALINA_HOME}/webapps/${ant.project.name}"></delete>
<copy todir="${env.CATALINA_HOME}/webapps" file="${build.dir}/${ant.project.name}.war"/>
<exec executable="${env.CATALINA_HOME}/bin/startup.bat"/>
</target>
<!--you can ignore-->
<target name="email" depends="war">
<mail mailhost="****@************" mailport="465" user="******@163.com" password="**************" subject="Test build">
<from address="****@************"/>
<replyto address="****@************"/>
<to address="****@************"/>
<message>The build has completed</message>
</mail>
</target>
</project>```
#console question
1.env.CATALINA_HOME -------------------you need to config in path
2.you will find jstl1.2 can't be used in it.----------- change it
3.```<project name="testSpring" default="war" basedir=".">``` at the first line,you can change the default,If you buid in eclipse,you can choose different way to run.In linux,you need to write it.
#console
I will update it.thank you for read it,you can contact me.[My communication](http://www.jianshu.com/writer#/notebooks/5708790/notes/5275406)