Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Some Recipes to Improve Your Google Web Toolkit Development

Experiences, tips and techniques to assist you in creating GWT Web applications.

  • Print
  • Feedback

Page 3 of 6

  • Server-side code: Contains your servlet code, if your server-side is made up by Java servlets. If you are using Tomcat 5.5 or Tomcat 6, you can use the full power of Java 5+ here. Enable Eclipse compiler settings per project, and use the Java 5 compiler settings with compliance level set to "5.0". You can also enable all of the Eclipse "Compiler->Error/Warnings" features that meet your needs, e.g., to address missing @override annotations or the like. If you have Eclipse 3.2.2, then its new "Source->Clean up" feature is also worth configuring. The name of this project is <ModuleName>-server', e.g., "JUnit2MR-server", and it depends on the <ModuleName>-rpc project in your build path settings. The package name is <com.company.project>.gwt.<ModuleName>.server, if you are programming according to GWT's default package proposals.

  • You can see the resulting directory structure for our example application in figure 1. If you look inside the JUnit2MR-client directory, you can see additional directories created during the deployment process, as well as an Eclipse launch configuration to start our GWT application "JUnit2MR" in hosted mode. My tip is to collect project-specific jar files in a directory called "lib", e.g., inside JUnit2MR-client/lib we have GWT add-on libraries like "gwt-tk" or "gwt-login". You can find a good list of third-party client-side GWT add-ons at the GWT Unofficial Wiki site (see Resources). The RPC-project does not need a lib directory in my case statudy, but the server-side project's lib directory will contain only jar files needed by your servlet code.

    Using this three-projects GWT structure, the Eclipse launch configuration for your application in the GWT hosted mode is a little bit more complicated than having only one project. Therefore, I provide a screenshot in figure 2 that shows the necessary settings for my case study.

    Figure 1: Eclipse project directory structure for client, rpc, and server-part

    Figure 1: Eclipse project directory structure for client, rpc, and server-part

    Figure 2: Eclipse launch configuration for GWT hosted mode

    Figure 2: Eclipse launch configuration for GWT hosted mode

    You can do even more on structuring your code by establishing a separate Java "rpc" package inside the client and rpc project. In the rpc project it will just replace the "client" package still containing your transfer objects and the asynchronous interface definitions. In the client project the "rpc" package must be added, and it will include your synchronous interface definitions (without the callback parameter) moved from the client packag e. The only thing left is to make the new rpc package known to GWT by adding the <source path="client"/><source path="rpc"/> statements to your GWT module description.

    Tip 2: Debugging and Error Reporting: there is more than Window.alert ()

    It's true: you can actually use your IDE's full debugging capabilities when creating GWT applications. But before digging into where the error may have occurred, you need solid exception reporting on both the client and the server side of your code. This is typically done with try/catch blocks. Inside a client-side catch block you should pay attention to the fact that the default method call e.printStackTrace() is not a suitable solution in all situations. It will work when running your application in GWT hosted mode, printing text to your Eclipse console. However, for web mode ask yourself: "Where will my stacktrace and error messages that I have sent to stdout or stderr be displayed?" One possible solution is to use Mat Gessel's debug utility classes (see Resources) but you need a browser JavaScript console to see the results in web mode.

    • Print
    • Feedback

    Resources

    Google Web Toolkit home page

    GWT Unofficial Wiki page

    Introduction to GWT development: Ease AJAX development with the Google Web Toolkit

    GWT add-on for debugging, developed by Mat Gessel.

    GUI-based GWT testing with Selenium

    For a good Ant script to deploy your GWT applications to Tomcat see: Google Web Toolkit: AJAX Buzz Meets Real World Development

    Groovy Gant

    To get the Gant script and the corresponding build.properties file for easy GWT deployment to Tomcat, download sample code.