About Ant(the build environment of java)

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.reibang.com/writer#/notebooks/5708790/notes/5275406)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市棋傍,隨后出現(xiàn)的幾起案子退疫,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,640評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件缤至,死亡現(xiàn)場離奇詭異,居然都是意外死亡寒砖,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,254評論 3 395
  • 文/潘曉璐 我一進店門嫉拐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來哩都,“玉大人,你說我怎么就攤上這事椭岩∶┐” “怎么了璃赡?”我有些...
    開封第一講書人閱讀 165,011評論 0 355
  • 文/不壞的土叔 我叫張陵判哥,是天一觀的道長。 經(jīng)常有香客問我碉考,道長塌计,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,755評論 1 294
  • 正文 為了忘掉前任侯谁,我火速辦了婚禮锌仅,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘墙贱。我一直安慰自己热芹,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,774評論 6 392
  • 文/花漫 我一把揭開白布惨撇。 她就那樣靜靜地躺著伊脓,像睡著了一般。 火紅的嫁衣襯著肌膚如雪魁衙。 梳的紋絲不亂的頭發(fā)上报腔,一...
    開封第一講書人閱讀 51,610評論 1 305
  • 那天株搔,我揣著相機與錄音,去河邊找鬼纯蛾。 笑死纤房,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的翻诉。 我是一名探鬼主播炮姨,決...
    沈念sama閱讀 40,352評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼米丘!你這毒婦竟也來了剑令?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,257評論 0 276
  • 序言:老撾萬榮一對情侶失蹤拄查,失蹤者是張志新(化名)和其女友劉穎吁津,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體堕扶,經(jīng)...
    沈念sama閱讀 45,717評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡碍脏,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,894評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了稍算。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片典尾。...
    茶點故事閱讀 40,021評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖糊探,靈堂內(nèi)的尸體忽然破棺而出钾埂,到底是詐尸還是另有隱情,我是刑警寧澤科平,帶...
    沈念sama閱讀 35,735評論 5 346
  • 正文 年R本政府宣布褥紫,位于F島的核電站,受9級特大地震影響瞪慧,放射性物質(zhì)發(fā)生泄漏髓考。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,354評論 3 330
  • 文/蒙蒙 一弃酌、第九天 我趴在偏房一處隱蔽的房頂上張望氨菇。 院中可真熱鬧,春花似錦妓湘、人聲如沸查蓉。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,936評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽豌研。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間聂沙,已是汗流浹背秆麸。 一陣腳步聲響...
    開封第一講書人閱讀 33,054評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留及汉,地道東北人沮趣。 一個月前我還...
    沈念sama閱讀 48,224評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像坷随,于是被迫代替她去往敵國和親房铭。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,974評論 2 355

推薦閱讀更多精彩內(nèi)容