java ant build.xml文件詳細解釋

<?xml version="1.0" encoding="UTF-8"?>                                    
                                     
<project name="ant_firsttest" default="dist" basedir=".">                                    
  <description>ant firsttest!</description>                                    
                                        
  <!-- set global properties for this build -->        
  <!--設定變量,以後用。location爲文件夾路徑-->                            
  <property name="src" location="src"/>                                    
  <property name="build" location="build"/>                                    
  <property name="dist"  location="dist"/>                                    
  <property name="web"  location="web"/>                                    
           
  <!--設置properties文件位置.這裏沒用到。-->                                       
  <!--<property file="nbproject/project.properties"/>-->                                    

  <!--初始化命令-->                                    
  <target name="init">                                    
    <!-- Create the time stamp -->                                    
    <tstamp/>                                    
                
    <!--mkdir是創建文件夾,${build}即剛纔設定的變量。這幾行都在幹這事。-->    
    <!-- Create the build directory structure used by compile -->                                    
    <mkdir dir="${build}/WEB-INF/lib"/>                                    
    <mkdir dir="${build}/WEB-INF/classes"/>                                    
                                          
    <mkdir dir="${build}/WEB-INF/classes/javafile/package1"/>                                          
    <mkdir dir="${build}/WEB-INF/classes/javafile/package2"/>                                               
                                         
  </target>                                    

  <!--編譯-->                                    
  <target name="compile" depends="init"                                    
        description
="compile the source " >                                    
                                            
    <!-- Compile the java code from ${src} into ${build} -->                                    
    <!--javac標籤用來設置編譯程序的參數,srcdir爲java文件路徑,destdir爲編譯後class文件的保存路徑。-->
    <javac srcdir="${src}/javafile/package1" destdir="${build}/WEB-INF/classes/javafile/package1"/>                                    
    <javac srcdir="${src}/javafile/package2" destdir="${build}/WEB-INF/classes/javafile/package2"/>                                    
    <!--若是路徑下還有別的文件須要一塊兒打包,用copy 命令。-->    
    <copy file="${src}/hello_ant.xml" tofile="${build}/WEB-INF/classes/hello_ant.xml" />                                                                             
                                        
  </target>                                    
            
  <!--編譯後就要打包了。-->                                    
  <target name="dist" depends="compile"                                    
        description
="generate the distribution" >                                    
    <!-- Create the distribution directory -->                                    
    <mkdir dir="${dist}"/>                                    
                      
       <!--像jsp,jar這些直接用不用編譯的文件,直接用copy命令。-->                                
    <copy file="${web}/image/a.gif" tofile="${build}/image/a.gif" />                                    
    <copy file="${web}/WEB-INF/web.xml" tofile="${build}/WEB-INF/web.xml" />                                     
    <copy file="${web}/WEB-INF/lib/a.jar" tofile="${build}/WEB-INF/lib/a.jar" />                                          
    <copy file="${web}/index.jsp" tofile="${build}/index.jsp" />                                     
            
    <!--最後用jar命令打成jar/war文件,文件名和後綴隨便起。basedir爲欲打包的原文件路經-->                                    
    <jar jarfile="${dist}/ant_firsttest.jar" basedir="${build}"/>                                    
  </target>                                    
    
  <!--刪除-->
  <target name="clean"                                    
        description
="clean up" >                                    
    <!--設定刪除命令要刪的路徑。-->    
    <!-- Delete the ${build} and ${dist} directory trees -->                                    
    <delete dir="${build}"/>                                    
    <delete dir="${dist}"/>                                    
  </target>                                    
</project>                                        
java

4.控制檯在firsttest目錄,輸入ant後回車就打包完成了!
  注:輸入ant回車自動執行init,compile,dist命令。要想執行clean命令,輸入ant clean便可。web

相關文章
相關標籤/搜索