天天看點

ant中調用外部ant任務的兩種方法

在ant腳本中對外部ant任務的調用,在多項目管理中特别有用。兩種方法總結一下:

使用antfile、使用exec

一:使用antfile

    <target name="copy_lib" description="Copy library files from  project1 to project2">

          <ant antfile="build.xml"

              dir="${project1dir}"

              inheritall="false"

              inheritrefs="false"

              target="copy_to_project2_lib"

          />

    </target>

antfile表示子項目的建構檔案。

dir表示建構檔案所再的目錄,預設為目前目錄。

inheritall表示父項目的所有屬性在子項目中都可使用,并覆寫子項目中的同名屬性。預設為true。  

inheritrefs表示父項目中的所有引用在子項目中都可以使用,并且不覆寫子項目中的同名引用。預設為false。

如果在ant任務中顯示的定義引用,如上例<reference refid="filter.set">則該引用将會覆寫子項目中的同名引用。   

target表示所要運作的子項目中的target,如果不寫則為預設target。

二:使用exec

        <exec executable="cmd.exe">

            <arg line="/c "cd ../project1 && ant copy_to_project2_lib " "/>

    </exec>

翻譯為指令行就是:cmd.exe /c "cd ../project && ant copy_to_project2_lib"  

意思是直接調用系統控制台,先執行cd指令,再執行ant腳本指定任務,/c 表示執行後續 String 指定的指令,然後停止。