This section describes the GWT application files generated by the GWT compiler and the different ways to deploy these resources on your web server or servlet container to get your GWT application up and running. Before reading about deploying your GWT application, it is also important to understand the GWT compiler, and the output it generates.
Deploying a GWT application to a web server is straightforward. All you need to do is copy the generated GWT application files after compilation and host them on your web server. You will also need to setup your server-side code, of course, and this setup can take on a number of different forms: communicating through JSONP and working with JSON data, server-side scripts that receive and parse HTTP requests sent through the GWT RequestBuilder, or GWT RPC (see “Deploying on a servlet container using RPC” section below).
For an example of deploying GWT application files to a web server, suppose you want to deploy the DynaTable application on a web server, serving files from
/web/apps/dynatable_app/. Once you’ve run the GWT compiler and generated the output in the
war/dynatable directory, all you need to do is copy the host HTML page and stylesheet over to
web/apps/dynatable_app/ and copy the contents of the
war/dynatable subdirectory to
/web/apps/dynatable_app/dynatable/. At this point, the application is deployed. However, there are a few important points to keep in mind to make sure your application is properly deployed:
- The host HTML page can actually reside anywhere on your web server.
- The bootstrap script can also reside anywhere on your web server.
- The GWT application files must reside in the same directory as the bootstrap script, since the script looks for the application files relative to its own location.
- The host HTML page must reference the bootstrap script in its appropriate location on the web server.
- Any public resources can also be placed anywhere on the web server, but these should ideally mirror the resources’ path relative to the war folder during development. Otherwise, references to these resources might not hold when deployed (e,g, an Image widget referencing some .png file).
Deploying a GWT application on a servlet container is also an easy process. Since the GWT compiler generates output in a directory structure that is already compliant to the Servlet 2.5 API specification, you can deploy your application from the output directory itself. It would be better practice to copy the output and deploy it to a separate directory on your servlet container, however.
Referring to the DynaTable sample, deploying your project would involve copying the GWT compiler output to the following path on your servlet container:
webapps/dynatable/DynaTable.html webapps/dynatable/DynaTable.css webapps/dynatable/dynatable/dynatable.nocache.js // The rest of your GWT application files under webapps/dynatable/dynatable/
There are a few extra steps to take to make sure that your application is ready for deployment on the servlet container.
The build script generated by the webAppCreator utility automatically takes care of compiling your servlet classes and placing them in the
war/WEB-INF/classes folder. However, it is possible that your resources may fall out of sync as you make changes to your server-side code that don’t necessarily incur changes in your GWT client-side code, and hence you may forget to run the compiler to generate the new
.class files for your servlet classes. In such cases, you could run the build script over your application code once more to generate the new
.class files, but a simple javac would also suffice and probably take less time to compile. If the RPC service method signatures have changed, however, then you will need to re-compile your application with the GWT compiler.
Any other server-side classes will also need to be placed in this directory, in accordance with the Servlet API specification.
Any servlet you’re using in your application, including GWT RPC servlets, will need to be defined in the
web.xml file. In previous versions, GWT required you to define servlets in the module XML file in order for them to be resolved in development mode. This is no longer the case, and the
web.xml file is used to configure servlets for both development mode and deployed production mode.
The lib folder contains the various libraries (typically JAR and class files) that your application uses. Among the various server-side libraries your application uses, the
gwt-servlet.jar should also go here if your application uses GWT RPC. The
build.xml configuration file generated by the
webAppCreator utility should take care of copying this resource to the lib directory for you. To copy other required libraries in the lib folder, you can either add them manually or update the build script to copy over libraries from your project classpath.
The serialization policy file
If you’re using GWT RPC, the GWT compiler will have emitted an
<md5>.gwt.rpc serialization policy file after compilation. This file must be deployed on your servlet container in order for the GWT RPC mechanism to determine whether it’s safe to serialize types passed into your GWT RPC services. The serialization policy file can live anywhere in your webapp application directory, as long as it is retrievable via the ServletContext.getResource() call in your RPC service.
If you’re using GWT RPC in your application, you can check out documentation on deploying RPC services for more details.
Note: To run through the steps to deploy a GWT application to Google App Engine, see the tutorial Deploying to Google App Engine.
Deploying your application on Google App Engine only takes a couple of steps. First, you need to compile your application with the GWT compiler to generate the application files in the standard war directory structure, then you can upload and deploy your application using the appcfg utility.
If you used the
webAppCreator to create your project, you can simply compile your application with:
and then deploy your application from the war output directory by invoking the appcfg utility with the update option:
<appengine_home_dir>/appcfg.sh update war
You will need to have your appengine-web.xml properly configured beforehand, as well as ensure that you have created a Google App Engine account and an application space for your GWT application. You can read the App Engine docs for more information.