ant—學習記錄一

<?xml version="1.0"?>
<project name="helloWorld">
<target name="sayHelloWorld">
<echo message="Hello,xutianhao"/>
</target>
</project>
<!-- ant_helloworld -->

  

 

<?xml version="1.0"?>
<project name="projectStudy" default="sayBaseDir" basedir="E:\apache-ant-1.8.2-bin\apache-ant-1.8.2">
<!-- default 表明默認要執行的動做  target-->
<!-- basedir爲用戶設置的屬性 若是去掉的話再執行,結果是e:即ant構建文件的父目錄 -->
<target name="sayBaseDir">
<!-- 命令行中執行的語句  ant SayBasedir 即執行sayBaseDir步驟 -->
<!-- 若是未指明執行的target 直接ant 會完成default指定的target-->
<echo message="the base dir is:${basedir}"/>
</target>
<!-- 若是說在一個project裏有兩個name相同的target 
運行結果爲
BUILD FAILED
E:\build.xml:20: Duplicate target 'sayBaseDir'-->
</project>

  

 

<?xml version="1.0"?>

<project name="targetStudy">
<target name="targetA" if="ant.java.version">
<!-- 若是 if屬性存在 所在 target將被執行 -->
<echo message="java.version:${ant.java.version}"/>
</target>
<target name="targetB" unless="amigo" depends="targetA">
<!-- 若是 unless屬性存在 所在target將不被執行 -->
<!-- targetB依賴於targetA -->
<!-- 運行ant targetB 先執行targetA(被依賴的)再執行targetB -->
<description>a depend example!</description>
<echo message="The base dir is:${basedir}"/>
</target>
</project>

<!--運行結果
E:\>ant targetB
Buildfile: E:\build.xml

targetA:
     [echo] java.version:1.7

targetB:
     [echo] The base dir is:E:\

BUILD SUCCESSFUL
Total time: 0 seconds -->

  

 

<?xml version="1.0"?>

<project name="targetStudy">
<target name="targetA">
<echo message="The base dir is:${basedir}"/>
<!-- project 基目錄的絕對路徑   表明當前目錄-->
<echo message="The ant.file is:${ant.file}"/>
<!-- buildfile 的絕對路徑 -->
<echo message="The ant.java.version is:${ant.java.version}"/>
<!-- ant 檢測到的java版本  -->
<echo message="The ant.version is:${ant.version}"/>
<!-- ant 的版本 -->
<echo message="The ant.project.name is:${ant.project.name}"/>
<!-- 當前制定的project的name -->

</target>
</project>
<!-- E:\>ant targetA
Buildfile: E:\build.xml

targetA:
     [echo] The base dir is:E:\
     [echo] The base dir is:E:\build.xml
     [echo] The base dir is:1.7
     [echo] The base dir is:Apache Ant(TM) version 1.8.2 compiled on December 20
 2010
     [echo] The base dir is:targetStudy

BUILD SUCCESSFUL
Total time: 0 seconds -->

  

 

 

<?xml version="1.0"?>

<project name="targetStudy">
<property name="name" value="xutianhao"/>
<property name="age"  value="23"/>
<target name="targetA">
<echo message="The base dir is:${name}"/>
<!-- 設置的姓名屬性 xutianhao-->
<echo message="The base dir is:${age}"/>
<!-- 設置的年齡屬性23-->

</target>
</project>
相關文章
相關標籤/搜索