A guide to Ant, an advanced build system: Difference between revisions

From Elvanör's Technical Wiki
Jump to navigation Jump to search
No edit summary
 
Line 18: Line 18:


* To be able to reference a variable and expand it (eg, for ${DeploymentDirectory} to be replaced by /var/www/), you must use a property (here, with the name "DeploymentDirectory"). It won't work if you try to reference an XML node, for example.
* To be able to reference a variable and expand it (eg, for ${DeploymentDirectory} to be replaced by /var/www/), you must use a property (here, with the name "DeploymentDirectory"). It won't work if you try to reference an XML node, for example.
* In the javac task, don't include part of the package structure in the <tt>srcdir</tt> attribute. Eg, don't write <tt>srcdir=src/com/example/</tt>. Else it will confuse Ant, and Ant will rebuild every Java source file at every run.

Revision as of 13:51, 28 March 2007

Ant is a very advanced and flexible build system. It seems really modular and able to accomplish a lot of tasks. However, it also seems complex to understand and learn.

The Basics

  • Ant build files are XML files.
  • These XML buildfiles (default name, like "Makefile" for GNU Make, is "build.xml") contain a list of targets. A target itself contains a list of tasks.
  • A task is anything Ant can do: it can launch a Java compilation, copy files to a directory, and LOTS of other stuff.

Hints & Tips

  • To import another file from a first one, you can use the import task:
<import file="configuration.ant.xml"/>

In this case, the imported file must be a valid Ant XML file. You can also (more easily) just include a list of properties from a file directly with the property task.

  • To be able to reference a variable and expand it (eg, for ${DeploymentDirectory} to be replaced by /var/www/), you must use a property (here, with the name "DeploymentDirectory"). It won't work if you try to reference an XML node, for example.
  • In the javac task, don't include part of the package structure in the srcdir attribute. Eg, don't write srcdir=src/com/example/. Else it will confuse Ant, and Ant will rebuild every Java source file at every run.