# Ant 使用概述

**URL:** <https://www.isharkfly.com/t/ant/11118>\
**Category:** DevOps\
**Created:** [June 23, 2011, 11:24pm UTC](https://www.isharkfly.com/t/ant/11118 "2011-06-23T23:24:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [June 23, 2011, 11:24pm UTC](https://www.isharkfly.com/t/ant/11118/1 "2011-06-23T23:24:40Z")

</div>

使用ant 也同样是非常简单的事。通常的做法就是在你的项目里面建立一个XML文件，名字通常可以取 build.xml 。

当然你可以取任何你喜欢的名字。

这个文件就是你需要ant为你项目做的一些辅助性工作的批处理文件。`<?xml version="1.0" encoding="utf-8"?>
<project default="all" name="pluto-project" basedir=".">
  <target name="all" depends="api, container, portal"></target>
  <target name="clean"
  depends="api-clean, container-clean, portal-clean"></target>
  <target name="api">
    <property name="final.name" value="portlet-api-@@DATE@@" />
    <ant antfile="build.xml" dir="api" target="jar"
    inheritAll="false" />
  </target>
  <target name="api-clean">
    <ant antfile="build.xml" dir="api" target="clean"
    inheritAll="false" />
  </target>
  <target name="container" depends="api">
    <ant antfile="build.xml" dir="container" target="jar"
    inheritAll="false" />
  </target>
  <target name="container-clean">
    <ant antfile="build.xml" dir="container" target="clean"
    inheritAll="false" />
  </target>
  <target name="portal" depends="container">
    <ant antfile="build.xml" dir="portal" target="jar"
    inheritAll="false" />
  </target>
  <target name="portal-clean">
    <ant antfile="build.xml" dir="portal" target="clean"
    inheritAll="false" />
  </target>
</project>
`这个build.xml 文件引自apache的一个项目。

里面可以看到有 project 以及target 标签。

有些项目的build.xml可能不是以“?xml version=“1.0” encoding=“UTF-8”?”开头的，不过没关系。

每一个build.xml 只能有一个project 标签， 每个project 标签里面包含了几个tartget标签。每一个target可以独立执行或者依赖于其他target执行完毕才能执行。
