There are 2 ways to execute Python scripts in Ant:
JSR-223 enables dynamic languages to be callable via Java in a seamless manner. Unfortunately this is currently only supported with Jython 2.2.1 and not the latest 2.5.0. Since PyAMF only supports Jython 2.5 or newer, you have to use the PythonInterpreter class directly. This style of embedding code is very similar to making use of a scripting engine, but it has the advantage of working with Jython 2.5.
Here you see the gateway running in Ant:
[mkdir] Created dir: build/classes
[javac] Compiling 1 source file to build/classes
[mkdir] Created dir: build/jar
[jar] Building jar: build/jar/HelloWorld.jar
[java] *sys-package-mgr*: processing new jar, 'build/jar/HelloWorld.jar'
[java] Running AMF gateway on http://localhost:8000
Read the complete howto, including a sample server/client, on http://pyamf.org/tutorials/jython/ant.html.
Today a new tutorial was added that shows you how to deploy your PyAMF applications with Apache Tomcat and modjy. modjy is an implementation of a WSGI compliant gateway/server for Jython, built on Java/J2EE servlets. This allows you to run Jython WSGI applications inside a Java/J2EE servlet container, e.g. Apache Tomcat. modjy is part of the Jython project.
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!
We created a Guestbook Example to demonstrate a full featured application using Flex, Twisted, and PyAMF of course.
In this tutorial, I'll run through how to get a remoting server setup that deals with authentication. I'll assume that you already have the latest version of PyAMF installed (at the time of writing, 0.1b is the most recent version).
I am going to build a WSGI remoting gateway, but you can use the principles applied here to any of the other supported gateway implementations (Django or Twisted). Check out the tutorials for more info.
The Socket class enables Actionscript to make socket connections and to read and write raw binary data. This example shows how to:
- use the Twisted framework and PyAMF to create a socket server
- create a connection with the socket server using Flex and Actionscript
- send the system time from Python to the Flash Player as Actionscript Date object, with an interval of 1 second
We have created a simple PyAMF example for the ByteArray class in ActionScript which provides methods and properties to optimize reading, writing, and working with binary data. The PyAMF equivalent of this class is also called ByteArray that provides the same basic functionality.