If you develop Java applications, chances are you’ve used Apache Ant in integration with Eclipse. The Ant view pane allows easy access to the build automation tasks your project may have defined. In the PHP world, we have a build system based on Ant called Phing. This article will show you how to easily access your Phing tasks in Eclipse [PDT].
If you’re new to Phing, please check out Phing.info.
Phing: build.xml
The example below defines a single task: help in a file called build.xml.
<?xml version="1.0" encoding="UTF-8"?> <project name="example" basedir="." default="help"> <target name="help"> <echo> Welcome to the phing script! ---------------------------- You may use the following commands: phing <target name> where <target name> can be one of the following: - help : this page </echo> </target> </project>
In the terminal, navigate to the folder where build.xml issue the following command “phing help”. This will execute and output our help text. phing is nice, but if you’re using Eclipse, you may want to access the tasks from the IDE itself.
Ant: ant-build.xml
Eclipse comes with Ant support integrated as default. To use Phing with Eclipse, we will create an Ant XML file to wrap around our Phing task. Create the following file in the same folder as build.xml.
<?xml version="1.0" encoding="UTF-8"?> <project name="example"> <property name="phing.command" value="phing" /> <target name="help" description="Shows help information"> <exec dir="" executable="${phing.command}"> <arg line="help" /> </exec> </target> </project>
The property phing.command tells Ant where to locate phing on your machine. In my case, phing is located through PATH, but you could also specify the absolute path to your phing executable.
The example only has one task, which is help, the same as the phing example above. This wrapper executes a console application with arguments (arg line). Executing help will only run phing help, in the same folder as build.xml is stored.
To double click the help command in a GUI, we need to set up Ant in your Eclipse project.
- Open your Eclipse PHP Project where the XMl files are stored
- Turn on Ant view: Window -> Show View -> Other… -> Ant
- Drag ant-build.xml from the file explorer into the Ant View
- Double click example -> help to run the task. The results will show up in the Console view



September 19th, 2008 at 12:37 pm
Phing looks almost exactly like ANT? Why when ANT comes preinstalled in most versions of Eclipse would you ever want to use Phing?
September 21st, 2008 at 11:08 pm
Generally Ant requires Java and Phing requires PHP. In addition Phing has some PHP specific tasks which make it a more natural choice for PHP developers.
October 12th, 2008 at 5:35 pm
Thanks for this tip! We had customized the phing bootstrap to be run using Zend Studio’s “Run as PHP Script” tool, but this is a much more elegant solution.