Getting started with Jython and Apache Ant

Today I decided to introduce some Jython in one of our build scripts at work because it was simply too painful to use a pure Ant script. It would/ve been nice to avoid the Jython dependency but after screwing around with Ant for a few hours I decided to write a Python script to do the job.

Although the Ant documentation for the Script task is pretty good it wasn't dead simple to hook up Jython to Ant, and because I couldn't find any examples online I decided to create a simple example so others might benefit from it. All files (except for the .jar's) are available in the sandbox of the PyAMF repository.


  1. Download Jython and the JSR 223 scripting engine .jar files for Jython
  2. Externalize some paths in a file (optional)
  3. Create a Python test script that prints out some property defined in the Ant build file
  4. Create the Ant build.xml file that defines a Script task and includes the file

Run the Ant script on the console and it should output something like:

Buildfile: build.xml jython: [script] Apache Ant told Jython: Hello World! BUILD SUCCESSFUL Total time: 0 seconds

And that's it, a happy builder!


blog comments powered by Disqus