How to Get Started with PAnt

Follow these steps to to get started with PAnt:

  • Download Jython. Note that as of right now Jython 2.5 is somewhat slower to initialize than 2.2. You only need 2.5 if you want to be able to use decorators to create Ant targets.
  • Unzip jython distribution. Note: you need jython.jar and all files under Lib.
  • Download PAnt.
  • Extract pant.jar from PAnt distribution. This is the only file that you need at runtime in addition to jython itself.
  • Create a simple build.xml for bootstrapping PAnt or include the following code fragment into an existing Ant file. You can retrofit your existing scripts into python gradually. With PAnt, python code can happily co-exist with Ant XML.The bootstrapping XML file should include the following:



* Now the prep work is done and you can begin developing your build logic in python. The easiest way to do it is to create a python module and start creating targets and tasks, for example:

from pant.pant import ant, target

def ptarget2():
    """Python project ptarget2"""
    ant.echo("echo ptarget2")

* See this post for more information about creating targets in PAnt.
* Add “pimport” task to your build.xml:

* You can also create targets using PAnt APIs as opposed to decorators, as explained here. If that’s how you chose to do it, invoke the code that creates the targets using “jython” task:

* In Ant you can’t create a target from inside another target, so both “pimport” and “jython” have to be defined outside the “target” XML tag.

* You can run targets defined in python same way you run a regular Ant target: ant YOUR TARGET. PAnt doesn’t use a special shell scripts to run; you simply execute your “bootstrapping” build.xml using regular “ant” batch/shell script.

That’s it, the rest of it is simply writing your build logic in python using Ant tasks as documented here.