Two weeks ago I started to work with python and the django framework in order to deploy a web application in google app engine. (I am really amazed of how fast you can build web applications with python & django – but this will be another post :)
Since JavaFX is my favorite RIA technology I was wondering if we can deploy javafx applications on google app engine. So I started a new project and after 20 minutes it was ready. What surprised me the most is the fact that it is really easy to deploy javafx applications into google app engine. Keep in mind, however, that this is a simple example and I don’t access the database or other services that are offered by google app engine (maybe I will try that next year ;) .
What you really need to do is to pack your javafx application as an applet and place it under a folder in the google app engine application, declare that folder as a static resource in the app.yaml configuration file and finally use python to write it to the response.
Lets go through it step by step:
1. Create your javafx application and pack it as applet. For this example I will use the SpringAnimation of Josh Marinacci which you can find it here http://javafx.com/samples/SpringAnimation/index.html
2. Create a google app engine application. Instructions on how to create an app engine application can be found here
I have ported the google app engine application into eclipse and it looks something like this:
The most important files are the app.yaml where we need to declare that the javafx folder will serve static files and the mainapp.py python file which will serve our application.
Lets see the app.yaml file
So in the app.yaml configuration file we tell app engine that the application name is javafxtest, we declare the static folder under the handlers and we configure all the urls to be forwarded to the python file mainapp.py
Lets have a look at the python file
The content of this file is straightforward, we just write html code to the response. Note how we refer to the jar file and the folder that servers the static files. In the same folder with the jar file there is also the SpringAnimation_browser.jnlp file, we have to edit this file and change the codebase to the appropriate one (for me it was codebase=”http://localhost:9999/javafx/“) to test the application locally before uploading it, when you are about to upload it, change the codebase to the url of the app engine (for me it is codebase=”http://javafxtest.appspot.com/javafx”)
3. Upload the application in the app engine. The command to upload the application is python appcfg.py update <PROJECT_PATH>\JavaFXonGAE\src enter the email address and the password. You need to create an account if you do not have one.
You can find more info on how to deploy app engine applications here
You can access the application at http://javafxtest.appspot.com/
Google app engine: http://code.google.com/appengine/docs/gettingstarted/