For the past eight(8) years Schalk Neethling has been working as a freelance developer under the pseudo of Volume4 and is now the president of Overt Strategy Consulting. During this period he has completed over 300 projects ranging from full web application development to complete branding. As president and lead developer of Overt Strategy Consulting, Schalk Neethling and his team has released a 100% Java standards based content management system called AlliedBridge and business document exchange and review system, called Doc-Central. Schalk Neethling is also actively involved on a daily basis in the open source, web standards and accessibility areas and is a current active member of the Web Standards Group. Schalk is also the co-founder and president of the non-profit The South Web Standards and Accessibility Group, which aims to actively educate and raise awareness of web standards and accessibility to both the developer society as well as business large and small. Schalk also has a long relationship with DZone and is currently zone leader for both the web builder,, as well as the .NET zone,, and you can find a lot of his writing there as well as on his blog located at Schalk is constantly expanding on his knowledge of various aspects of technology and loves to stay in touch with the latest happenings. For Schalk web development and the internet is not just a job, it is a love, a passion and a life style. Schalk has posted 173 posts at DZone. View Full User Profile

GWT: Running a completed project

  • submit to reddit

Let's put GWTShell and GWTCompiler to use with a calculator example, CalculatorWidget. First, we'll use GWTShell to get the lay of the land and launch the hosted mode browser. This is how you typically run and debug a project while in hosted mode during development. Then we'll move on to compiling things with GWTCompiler, which is what is normally used as part of a build process to turn your Java into JavaScript and create a deployable artifact for web mode.

Hosted mode and the GWT shell

When you run ApplicationCreator, GWT creates some shortcut scripts for invoking GWTShell and GWTCompiler with the project. For this example, we'll first execute GWTShell using the [PROJECT_HOME]/Calculator-shell script (it will have a platform-dependent extension). The next step is to ensure that the environment is configured as it needs to be to support GWT and the project itself, and then invoke Calculator-shell. It should successfully invoke the example in the shell as shown in figure 1.

Figure 1 The GWT shell and hosted mode browser running CalculatorWidget

The background window in figure 1 is the GWT shell, and the foreground is the hosted mode browser running CalculatorWidget. The GWT shell includes a logging console where any problems will be displayed. This includes exceptions, which are passed up the call stack. The shell also includes buttons for manipulating the log and launching the hosted mode browser.

Can the GWT shell browser be specified?

When you launch the GWT shell, you'll notice that the hosted mode browser is the system browser for the platform you are using. This means Internet Explorer on Windows, Safari on Mac, and Mozilla Firefox on Linux. The hosted mode browser is actually based on SWT browser components, so it is not currently possible to specify or configure which browser is used when running the shell. (This will change in the near future with out-of-process hosted mode, which will allow you to use any supported browser on a platform.)

Recall that the shell and the hosted mode browser execute your project as Java bytecode, as opposed to JavaScript, when executed in web mode (which we'll get to in a moment). This means that from hosted mode, in addition to being able to quickly recompile your code with the Refresh button, you can also use Java debuggers and profilers, as you normally would with any Java project.

To connect to the GWT shell for the purposes of debugging, you can use the Java Platform Debugger Architecture (JPDA), which is built into most JVM implementations, and your favorite IDE. By invoking with the following command-line options, you can force the GWT shell to delay startup until a debugger has connected:

-Xdebug -Xnoagent -Djava.compiler=NONE

Using this technique, you can run the shell outside of your IDE, and then connect to it with Eclipse, or NetBeans, or such, at localhost:8888. Once this connection is made, the socket listener resets to the HTTP listener from the shell and you can continue your step-through debugging as you normally would.

Within the hosted mode browser, you'll notice the standard browser navigation buttons and a special Compile/Browse button that invokes the GWT compiler for the project. This takes you out of hosted mode (Java) and into web mode (JavaScript).

Web mode and the GWT compiler

GWTCompiler is the GWT facility that compiles your Java source path code into JavaScript, and bundles it with your public path resources in a deployable project form. The Compile/Browse button made available in the GWT shell will compile your project, deploy it in a stripped-down development version of Apache Tomcat on the local host (actually, the GWT shell also uses this mini Tomcat for any service servlets involved), and launch the project in the default configured browser for the machine. As the screenshot in figure 2 shows, the browser used for web mode can be specified (the machine default can be configured), so it can be different from the system browser that hosted mode must use inside the shell.

Figure 2 CalculatorWidget running in web mode, using Firefox on a Mac, after clicking the Compile/Browse button in the GWT shell

With the compile step, you are switching out of hosted mode and into web mode - running your code as JavaScript instead of directly as Java. In addition to the Compile/Browse button in the shell, the shortcut ProjectName-compile script, created by ApplicationCreator, can also be used to compile your project (which will place it by default in the [PROJECT_HOME]/www location). You can, of course, also use the GWT compiler manually, or with an IDE plugin, or by using build tools such as Ant or Maven.

This article is excerpted from Chapter 1 of GWT in Practice, by Robert Cooper and Charlie Collins, and published in May 2008 by Manning Publications.

Published at DZone with permission of its author, Schalk Neethling.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)