GWT Compiler and Web Mode

Two other files in the generated directory in Figure 2 jump out at us: the GwtAjax-Compile and GwtAjax-shell scripts. You can run these scripts from the command line, or dynamically from an Ant file. If your application was called XXX, then applicationCreator would call these files XXX-Compile and XXX-Shell.

The GwtAjax-Compile script uses a Java class to compile your Java code into a JavaScript file (if the code doesn't contain any errors). Once you have compiled the code, you can test or view the application in the browser(s). GWT refers to the latter development method as web mode.

An easy way to compile your code is to enter GwtAjax-Compile at the command line with no options. Figure 3 displays the description of the GwtAjax-Compile's various options such as -out or -style.

Running an XXX-Compile script to compile from Java code to JavaScript

Figure 3. Running an XXX-Compile script to compile from Java code to JavaScript

For example, if you type:

XXX-Compile -style PRETTY -out myapp

then the compiler will generate a non-obfuscated JavaScript file (where the code is easier to read for someone looking at the gwt.js file) inside a directory named myapp/fully-qualified-name-of-your-application-class. An example output directory from this shortcut's application is www/com.parkerriver.gwt.intro.GwtAjax. A directory named for a Java class is awkward to type into a browser, so you can change this directory name by using an Ant build ...

Get Google Web Toolkit for Ajax now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.