Tuesday, February 7, 2012

Ant Introduction and First Try


Ant is a Java-based build tool. In theory, it is kind of like Make, without Make's wrinkles and with the full portability of pure Java code.

To run ant build, several steps as below (with eclipse):

Step 1: Check the runtime environment:

Open Window -> Preferences

There should a tools.jar under Ant -> Runtime -> Global Entries

Step 2: Write a build file

Create a file named ant.firsttry.xml under root directory of a Project,
the code is as below:

<!-- The project entry, execute target firstTry at first -->
<project name="antTest" default="firstTry">
    <target name="preSet">
        <echo message="Preset of First Try"/>
    <!-- Echo message, will run the target preSet before it self -->
    <target name="firstTry" depends="preSet">
        <echo message="Ant First Try"/>

The default attribute of project tag denotes the default target to execute,
the depends attribute of target tag denotes the target that should be executed before.

In the case above, it will run target 'preSet' then 'firstTry'

Step 3: Run the ant build

Right click file ant.firsttry.xml, Run As -> Ant Build

The result will be

The full project is at github

File of this practice:


No comments:

Post a Comment