Chapter 6. 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.

Figure 6-1. 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 file later, or by using some other method.

After compiling, what does the output directory contain? Figure 4 shows the contents of the www/com.parkerriver.gwt.intro.GwtAjax directory.

Figure 6-2. The contents of the XXX-compile output directory


The directory certainly contains a lot of software artifacts! The gwt.js file contains the generated JavaScript. This directory also contains the HTML or XHTML that your users will load into their browsers (e.g., GwtAjax.html). The output also includes several files of the form C72EF04BD1BEF69CF1EC5772367A07B0.cache.html. These files are related to browser-specific versions of the generated JavaScript code, and will be part of the files (along with gwt.js) that you deploy to your production server. The XML files of the form C72EF04BD1BEF69CF1EC5772367A07B0.cache.xml do not have to be deployed. The GWT compiler class uses these files as metadata during the compilation process.




Google Web Toolkit for Ajax
Google Web Toolkit GWT Java AJAX Programming: A step-by-step to Google Web Toolkit for creating Ajax applications fast
ISBN: 1847191002
EAN: 2147483647
Year: 2006
Pages: 29

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net