ModjyGoogleAppEngine » History » Version 4
Alan Kennedy, 2009-04-13 01:36 AM
1 | 4 | Alan Kennedy | h1. Running jython WSGI applications on Google AppEngine, with modjy. |
---|---|---|---|
2 | 2 | Alan Kennedy | |
3 | 1 | Alan Kennedy | Now that "Google has added Java/JVM support to their AppEngine":http://googleappengine.blogspot.com/2009/04/seriously-this-time-new-language-on-app.html , it is now possible to run other JVM languages on it as well, including our favourite language "Jython":http://www.jython.org . |
4 | |||
5 | Modjy is the jython WSGI -> servlets gateway, used to bridge jython WSGI applications to running inside java servlet containers. And Google AppEngine is arguably one of the largest-scale servlet containers there is. And modjy can run applications on AppEngine. In order to do so, the following steps must be followed. "We contributed modjy to jython a few months back":http://jython.xhaus.com/?p=41 . |
||
6 | |||
7 | h2. Get a jython.jar suitable for running on AppEngine. |
||
8 | |||
9 | Because of the security constraints associated with running inside the AppEngine, e.g. not being allowed to write files, Google have provided "patches to the jython project":http://google-appengine-java.googlegroups.com/web/jython-r5996-appengine.patch to handle these concerns. |
||
10 | |||
11 | They also provided a pre-built jython.jar file, built with these patches applied, available from here: "Google's build of jython for AppEngine":http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine . But it doesn't work! (Seems that the jar was incompletely built, and excluded the *jar-complete* ant task in the jython build.xml file. |
||
12 | |||
13 | But worry not! We've built a fresh build of jython, from "trunk@revision 6218":http://fisheye3.atlassian.com/browse/jython/trunk , with the google patches applied, that works ( we checked!). You can download it from here: "jython.jar built for AppEngine":http://www.xhaus.com/jython-r6218-patched-for-appengine.jar . |
||
14 | |||
15 | h2. Making the jython library accessible. |
||
16 | |||
17 | The next limitation of Google's AppEngine is that you can only upload a limit of 1,000 files for any given web application. A lot of the code for modjy resides in the *Lib/modjy* directory of the jython distribution. The *Lib* directory is pretty big, and so exceeds the file limit. |
||
18 | |||
19 | The easiest way to get around this is to upload the Library in a zip file. Simply make a zip file of the contents of the *Lib* directory *within the directory itself*, i.e. the paths inside the zip file *should not start with *Lib/*. (You can download such a zip file below if you're concerned about getting it wrong). |
||
20 | |||
21 | Lastly, you have to add a *.pth* file which refers to your newly created *lib.zip*. It doesn't matter what that file is called, as long as it ends in *.pth*. So make a simple one line text file called *all.pth*, and put the text "lib.zip" on that one line. |
||
22 | |||
23 | 3 | Alan Kennedy | Place both the *all.pth* and the *lib.zip* file in the *WEB-INF/lib-python* directory of your web application, and you're good to go! |
24 | 1 | Alan Kennedy | |
25 | h2. Appengine application descriptor |
||
26 | |||
27 | When uploading applications to AppEngine, you also need to provide an "Application Descriptor":http://code.google.com/appengine/docs/java/config/appconfig.html . The file must reside in the web archive directory, inside *WEB-INF*, i.e. at the same level as the standard servlet *web.xml* file. |
||
28 | |||
29 | Here is the file that we use for the modjy demo application. |
||
30 | |||
31 | <pre> |
||
32 | <?xml version="1.0" encoding="utf-8"?> |
||
33 | <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> |
||
34 | <application>jywsgi</application> |
||
35 | <version>5</version> |
||
36 | </appengine-web-app> |
||
37 | </pre> |
||
38 | |||
39 | h2. Downloading the complete finished product. |
||
40 | |||
41 | If you don't want to go through all of the steps of building stuff yourself, and going through a trial-and-error process, you can download a complete version of the "modjy demo webapp for Google AppEngine":http://www.xhaus.com/modjy_webapp.zip . |
||
42 | |||
43 | Don't forget that you have to place the "jython.jar for Google AppEngine":http://www.xhaus.com/jython-r6218-patched-for-appengine.jar and place it into the *WEB-INF/lib* directory. |
||
44 | |||
45 | You will also have to place the AppEngine runtime api jar file in the *WEB-INF/lib* directory as well. It is located in the *lib/user* directory of the "AppEngine SDK download":http://code.google.com/appengine/downloads.html . |
||
46 | |||
47 | h2. Deploying to Google AppEngine. |
||
48 | |||
49 | To deploy the application, issue the following command |
||
50 | |||
51 | <pre> |
||
52 | $APP_ENGINE_SDK_HOME/bin/appcfg upload modjy_webapp |
||
53 | </pre> |
||
54 | |||
55 | And you should be up and running. |