Introduction To The Phing build.xml File

5th January 2009 - 3 minutes read time

By default, Phing will look for a file in the current working directory called build.xml when you run it. This document tells Phing what it will be doing during the build. You can change this by using the -f or the -buildfile property of phing and giving the build file as the parameter. The following code makes phing look for a build file called wibble.xml.

phing -f wibble.xml

Assuming that the project is called myProject, then a minimal buildfile would be look like the following:


Of course, this doesn't actually do anything at all, so it is utterly useless.

Every build file should consist of at a root project level, with one or more targets. Targets act as functions, they will copy your code to another directory, create a zip file, create documentation or do anything you want the build to do. You can run multiple targets, one after the other, by using the depends attribute. The following build file will run the first target before running the main target.

  1. <?xml version="1.0"??>
  2. <!-- This is a comment -->
  4. <project name="myProject" default="main">
  5. <target name="first"></target>
  6. <target name="main" depends="first"></target>
  7. </project>

When run this will output the following:

  1. C:\myProject>phing
  2. Buildfile: C:\myProject\build.xml
  4. myProject > first:
  6. myProject > main:
  10. Total time: 0.2197 seconds

You can call the targets whatever you want, but it is a good idea to call them by their functional name. You can also run single targets by running phing with an argument of the target in question. For example, if you want to run only the first target you would use the following command.

phing first

The target also supports the description attribute, which allows you to add a small description of that the target does. This is useful from a maintenance point of view, but also from a documentation point of view.


You can get phing to print out a list of the targets and their description by using the projecthelp flag like this.

  1. <code>phing -projecthelp</code>

This will print out the following.

  1. C:\myProject>phing -projecthelp
  2. Buildfile: C:\myProject\build.xml
  3. Default target:
  4. -------------------------------------------------------------------------------
  5. main The main and final target
  7. Main targets:
  8. -------------------------------------------------------------------------------
  9. first The first target
  10. main The main and final target

To actually do anything in a target you need to add in other xml tags. As a quick example you can echo text to the screen by using the echo tag. The following build file will print out a message to the screen when run.

  4. Have I built anything yet?

Automated Build With Phing

Add new comment

The content of this field is kept private and will not be shown publicly.