星期五, 5月 20, 2011

Google AppEngine + Vaadin



Google provides a scalable application hosting environment called Google App Engine (GAE). One of the many benefits of GAE is that hosting small scale applications is 100% free. Google starts charging for hosting when your application resource requirements start to grow.

    

      

  1. Install or update the Vaadin Eclipse Plugin to version 1.0 or newer. For more information see http://vaadin.com/eclipse.

   

  1. Read Google Eclipse plugin install instructions

  1. Create a new Vaadin project as described in the Book of Vaadin
    1. Select "Google App Engine servlet" as deployment type.
    2. Select to use Vaadin version 6.3.0 or newer. click "Download..." if it is not in the list.
  2. Enable GAE
    1. In project preferences check "Use Google App Engine" in Google/App Engine.
    2. Click the "My applications..." link
      1. Log into your Google App Engine account
      2. Create a new web application in "My Applications" list
      3. Add created the application id to your project configuration in Eclipse
  3. Code and configure your application.
  4. Deploy to App Engine by clicking the project with right mouse button and selecting Google/Deploy to App Engine, or click the "Deploy to App Engine" icon in the toolbar.
  5. Run the application in http://yourapplicationid.appspot.com/

Note! There is a problem in the latest GAE plugin which prevents this from working. If you get an error like "The App Engine SDK 'C:\<workspace path>\<project name>\war' on the project's build path is not valid" do the following:

  1. Open preferences -> Google -> App Engine and select the sdk version again
  2. Open prefercense -> Java Build Path -> Export Order. Change the Export order so that the App Engine SDK is ABOVE the "Web App Libraries" classpath container.

If you want to deploy the application in a normal servlet container outside GAE, always use com.vaadin.terminal.gwt.server.ApplicationServlet instead of com.vaadin.terminal.gwt.server.GAEApplicationServlet.

Google App Engine sets quite a few limitations for your application. Some of them are summarized below. You can read more about App Engine here. See also Wikipedia page for good summary of quotas.

Even though Google App Engine development environment is able to run your app locally, the execution environment differs a lot from the the real deployment environment. As a result, you often end up with the situation that the app runs locally without a problem, but doesn't in the cloud.

Your application and all classes it refers to must be serializable. Google App Engine serializes the session between each request and the application and all components are stored in the session. By extending a Vaadin class your class will automatically be serializable.

  • Data classes referred to must also be serializable
  • Never use "new Object()" to make a unique identifier as Object is not serializable.

To achieve the best performance, do not serve static files through the servlet. By default the widgetset and the theme is served through the servlet, which is nice for any other server than Google App Engine. In order to serve theme and widgetset outside the servlet, extract VAADIN directory from vaadin.jar to your WebContent. Note however that if you are using the free version of Google App Engine, there is a file limit which you may exceed if you have a large theme and/or widgetset and serve them statically.

Note that the server, the JVM where the servlet is running and basically everything will change from request to request. This means that you cannot count on that a static which is set during handling of one request will be set when handling the next request.

沒有留言: