认识ant

一、初体验:

新建文件:build.xml

<?xml version="1.0"?>
<project name="helloWorld">
  <target name="sayhelloWorld">
    <echo message="hello,anna"/>
  </target>
</project>

运行:进入对应的目录,ant sayHelloWorld

运行结果:

  sayHelloWorld:

    [echo] hello,anna

二、ant的关键元素

1.project元素

1)name属性  用于指定project的name

2)default属性 用于指定project执行时,默认执行的target名称

3)basedir属性  用于指定基本路径的位置  未指定时,使用ant构建文件的父目录作为基准目录

举例如下:

<?xml version="1.0"?>
<project name="projectStudy" default="sayBaseDir" basedir="D:\Program Files\apache-ant-1.9.16">
  <target name="sayBaseDir">
    <echo message="The base dir is: ${basedir}"/>
  </target>
</project>

编译运行: 进入对应目录,执行:ant sayBaseDir

运行结果:

sayBaseDir:

  【echo】The base dir is : D:\Program Files\apache-ant-1.9.16

注意:1)ant后面是target的名字; 2)${basedir} 调用了 project里basedir的具体内容

 

posted @ 2023-10-25 15:57  mei2023  阅读(33)  评论(0)    收藏  举报