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.
Steps:
- Download Jython 2.2.1 and the JSR 223 scripting engine .jar file for Jython
- Externalize some paths in a build.properties file (optional)
- Create a Python test script that prints out some property defined in the Ant build file
- Create the Ant build.xml file that defines a Script task and includes the build.properties file
- Run the Ant script on the console and it should output something like:
Buildfile: build.xmljython:
[script] Apache Ant told Jython: Hello World!BUILD SUCCESSFUL
Total time: 0 seconds
And that’s it, a happy builder!