标签:
<?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>
标签:
原文地址:http://www.cnblogs.com/tianhao/p/4220648.html