1、根節點使用,表示根目錄為當前目錄,默認啟動的target為build,項目名稱為othersysm,
<project basedir="." default="build" name="othersysm"> </project>
2、每一個target為一個執行命令,如果有依賴關系,則寫為:
<target depends="build-project" name="build"/>
表示要運行target,需要先運行build-project,根據此依賴關系,我們可以認為project節點中配置的default就是最后一個運行腳本
3、定義變量和路徑,使用定義的變量的方法為${變量名稱}
<property name="ibslib.location" value="../ibslib"/><property name="debuglevel" value="source,lines,vars"/><property name="target" value="6"/><property name="source" value="6"/>
3、定義jar包路徑,並命名,fileset表示引用外部包,pathelement表示內部
<path id="othersysm.classpath"> <pathelement path="{classpath}"/> <fileset dir="${ibslib.location}/lib/logging" includes="**/*.jar,**/*.zip"/> <pathelement location="bin"/> </classpath>
<target name="init">
<echo> +=======================================+ | init +=======================================+ </echo>
<mkdir dir="test"/>
<copy includeemptydirs="false" todir="test"><!--忽略空文件夾,並且拷貝到指定目錄-->
<fileset dir="src" excludes="**/*.launch, **/*.java"/><!--忽略指定文件-->
</copy>
</target>
5、編譯java文件,編譯命令為:
debuglevel:調試等級
destdir:編譯后的目標文件夾
source:源文件版本
target:目標文件版本
encoding:編碼
includeantruntime :指出是否應在類路徑中包括 Ant 運行時程序庫,默認為 yes
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/><!-- 打印ant腳本目錄 -->
<javac debug="true" debuglevel="${debuglevel}" destdir="test" source="${source}" target="${target}" encoding="UTF-8" includeantruntime="false">
<src path="src"/><!-- 源文件目錄 -->
<classpath refid="othersysm.classpath"/><!-- classpath目錄 -->
</javac>
</target>
antfile:需要運行的build文件
inheritAll 是否共享參數
target:運行的ant的target
output:輸出的日志文件
如果將參數傳遞,可以采用property
<ant antfile="${web.location}/build.xml" inheritAll="false" target="genwar" output="output.log"><property name="currentMode" value="${currentMode}"/><property name="targetMode" value="${targetMode}"/></ant>
<property file="${basedir}/build.properties"/>
8、替換文件中的指定值
<replaceregexp byline="true"> <regexp pattern="正則表達式"/> <substitution expression="將要替換的值"/> <fileset dir="${unpack.war.dir}/WEB-INF" includes="web.xml"/> </replaceregexp>
9、將文件夾打包為war包
<war destfile="${uibs.location}/web.war" webxml="WebContent/WEB-INF/web.xml"><fileset dir="WebContent" includes="**"/></war>
10、通過scp命令將上傳war包文件到指定機器的指定目錄
<scp file="${uibs.location}/${server.name}.war" todir="${wls.username}:${wls.password}@${remote.host}:${deploy.location}" trust="true"/>
11、遠程ssh,執行服務器命令,執行啟動腳本
<sshexec host="${remote.host}" username="${remote.username}" password="${remote.password}" command="ls" trust="true"/>