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.
- Download Jython and the JSR 223 scripting engine .jar files 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:
[script] Apache Ant told Jython: Hello World!
Total time: 0 seconds
And that's it, a happy builder!