Pradeep's Blog

Google

Sunday, September 17, 2006

Deploying AJAX application created using Google’s Web Toolkit

AJAX without java script! Few months back and I wouldn’t have believed this would be possible. With Google’s Web Toolkit you could code your AJAX applications in Java, and it converts it into Java script for you. Any application created using this Toolkit has three parts to it. First the client side code, this is the code that gets converted into Java script (and runs on the browser) , then the server side code this is the part of the application that runs in your web server (like Tomcat), then the public files, these can be any images or other files that are required by your application.

Since the client side code is translated into Java script, your client side code can only have features that a normal web browser can support (So features like Threads are not supported). In the server side code you can do any thing that Java supports.

The Google’s web toolkit supports two modes for running your AJAX applications. The first one is the hosted mode; this mode is very useful while developing the application. In this mode Google’s simulates the output of your application. The other mode is the web mode. In this mode the Java code is compiled into Java script code and you can run your application from a web server.


The documentation provided by Google for deploying the application in web mode is very limited. I recently deployed my application in Tomcat 5.5 and these are the steps that I followed,



1. Use the application.compile.cmd file to create all the client side files. These files would be placed in the www directory.
2. Get all the server side files compiled.

Consider that we are going to deploy in the ROOT directory in a tomcat.

1. Copy all the client side files (the content of the www directory) into the ROOT directory in tomcat.
2. Then copy all the classes (server side) files to ROOT/WEB-INF/Classes directory.
3. If there are any dependent jar files copy them to ROOT/WEB-INF/lib directory. [NOTE: The packages javax.servelt.*; have to be removed from both the jar files that are provided by Google].
4. Then map the server side servlets (the classes that talk to the client) via the web.xml file in the ROOT/WEB-INF directory.

The url pattern in the servlet mapping should be same in the client code, the application.gwt.xml and in the web.xml files.
If even after following these steps you have problems running you application in web mode, see your web server's logs for more information.