ModjyGoogleAppEngine
Version 8 (Alan Kennedy, 06/09/2009 02:49 pm)
| 1 | 4 | Alan Kennedy | h1. Running jython WSGI applications on Google AppEngine, with modjy. |
|---|---|---|---|
| 2 | 2 | Alan Kennedy | |
| 3 | 1 | 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 | 1 | ||
| 5 | 8 | Alan Kennedy | 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, follow these steps. "We contributed modjy to jython a few months back":http://jython.xhaus.com/?p=41 . |
| 6 | 1 | ||
| 7 | 8 | Alan Kennedy | Follow this link to see the "modjy demo application running on Google AppEngine":http://jywsgi.appspot.com |
| 8 | 8 | Alan Kennedy | |
| 9 | 1 | h2. Get a jython.jar suitable for running on AppEngine. |
|
| 10 | 1 | ||
| 11 | 8 | Alan Kennedy | Ever since the "patches provided by google to make jython run on Google Appengine":http://bugs.jython.org/issue1188 were applied to jython 2.5 at "revision 6252":http://fisheye3.atlassian.com/changelog/jython/?cs=6252 , the jython.jar supplied with the jython 2.5 distribution should run unmodified on Google Appengine. |
| 12 | 1 | ||
| 13 | 8 | Alan Kennedy | So you should use the jython.jar from the "latest version of jython":http://www.jython.org/ , which at the time of writing is Release Candidate 4, which will probably become the final jython 2.5.0 release. |
| 14 | 1 | ||
| 15 | 1 | h2. Making the jython library accessible. |
|
| 16 | 1 | ||
| 17 | 8 | Alan Kennedy | A 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 | 1 | ||
| 19 | 1 | 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 | 1 | ||
| 21 | 1 | 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 | 1 | ||
| 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 | ||
| 25 | 1 | h2. Appengine application descriptor |
|
| 26 | 1 | ||
| 27 | 6 | Alan Kennedy | When uploading applications to AppEngine, you also need to provide an "Application Descriptor":http://code.google.com/appengine/docs/java/config/appconfig.html , stored in a file called *appengine-web.xml*. 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 | 1 | ||
| 29 | 1 | Here is the file that we use for the modjy demo application. |
|
| 30 | 1 | ||
| 31 | 1 | <pre> |
|
| 32 | 1 | <?xml version="1.0" encoding="utf-8"?> |
|
| 33 | 1 | <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> |
|
| 34 | 1 | <application>jywsgi</application> |
|
| 35 | 1 | <version>5</version> |
|
| 36 | 1 | </appengine-web-app> |
|
| 37 | 1 | </pre> |
|
| 38 | 1 | ||
| 39 | 1 | h2. Downloading the complete finished product. |
|
| 40 | 1 | ||
| 41 | 8 | Alan Kennedy | We have provided a complete version of the "modjy demo application for Google AppEngine":http://downloads.xhaus.com/modjy_webapp_google_appengine/ for you to download. (This version is derived from jython 2.5RC4) |
| 42 | 1 | ||
| 43 | 8 | Alan Kennedy | Don't forget that you have to get a copy of the latest jython.jar and place it into the *WEB-INF/lib* directory. |
| 44 | 1 | ||
| 45 | 1 | 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 | 1 | ||
| 47 | 1 | h2. Deploying to Google AppEngine. |
|
| 48 | 1 | ||
| 49 | 1 | To deploy the application, issue the following command |
|
| 50 | 1 | ||
| 51 | 1 | <pre> |
|
| 52 | 8 | Alan Kennedy | $APP_ENGINE_SDK_HOME/bin/appcfg update modjy_webapp |
| 53 | 1 | </pre> |
|
| 54 | 1 | ||
| 55 | 1 | And you should be up and running. |