Working with the Google Web Toolkitby Robert Cooper
The Google Web Toolkit (GWT) was rolled out for JavaOne 2006 at an innocuously titled session. Due to what I assume was a timing miscommunication, the Google Blog scooped the presentation, but the impact was no less felt.
Figure 1. GWT includes a console window with hierarchical logging.
Figure 2. Java execution in the test browser allows for step-through debugging of code.
As they say, "But wait! There's more!" GWT also includes a basic RPC framework for making calls back to your server application in the form of a servlet. The
RemoteServiceServlet allows you to implement service methods on an implementation and expose these to your generated Ajax application. This is done by simply adding new
public methods to the servlet, and the GWT will handle serialization and deserialization to and from the client. How much would you pay for a framework like this? Don't answer yet!
GWT also includes a set of core DOM mapped classes and layouts that are more familiar to desktop application developers, such as the dock panel and horizontal panel. Prefabbed widgets such as
PopupPanel for context popups,
DialogBox for popup blocker friendly dialogs, and
StackPanel for Outlook-bar style displays. There is also a URI and History management system for maintaining a bookmarkable and "back buttonable" state through your application.
GWT is really just an executable Java application with some hooks into Tomcat and either Mozilla or MSIE under Linux and Windows, respectively (sorry Mac users, you are out of luck for now). When you download the GWT, it comes with several sample projects, including "KitchenSink," the GWT equivalent of SwingSet. You can run the batch file in the samples/KitchenSink directory to see it run. Two things will pop up: the GWT server monitor application and browser window where you can see the application run. Executing
java com.google.gwt.dev.GWTShell --help with your platform's *dev.jar and gwt-user.jar will show you the options available:
Google Web Toolkit 1.0.20 GWTShell [-port port-number] [-noserver] [-logLevel level] [-gen dir] [-out dir] [-style style] [-notHeadless] [url] where -port Runs an embedded Tomcat instance on the specified port (defaults to 8888) -noserver Prevents the embedded Tomcat server from running, even if a port is specified -logLevel The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL -gen The directory into which generated files will be written for review -out The directory to write output files into (defaults to current) -style Script output style: OBF[USCATED], PRETTY, or DETAILED (defaults to OBF) -notHeadless Causes the log window and browser windows to be displayed. Useful for debugging. and url Automatically launches the specified URL
Google includes an
applicationCreator script that will generate a set of batch files, scaffolding classes, and directories for a new GWT project. For our purposes here, however we are going to bypass this and start from scratch. First you will want the GWT Maven plugin installed. You can install this by unzipping the plugin project and typing
maven plugin:install-now. Also, you will want to copy the gwt-user.jar to ~/.maven/repository/com.google.gwt/jars/ manually. Since this JAR needs to be included in your final WAR file, it needs to be registered as a dependency in the Maven POM file.