gwt-windows-1.4.62.zip
with a program like WinZip. On Mac and Linux, you can
unpack the package with a command like tar xvzf gwt-mac-1.4.62.tar.gz
applicationCreator
, which is described below. It may be easiest to start out by building one of the sample applications shipped with GWT.All the sample applications are in the samples/
directory in your GWT package. Each sample has a script you can run to start it in hosted mode and a script you can use to compile it into JavaScript and HTML to run it web mode.
To run the Kitchen Sink sample in hosted mode, navigate to the samples/KitchenSink/
directory and run the KitchenSink-shell
script. This will open the GWT browser with the Kitchen Sink application running inside:
Since you're running in hosted mode, the application is running in the Java Virtual Machine (JVM). This is typically the mode you'll use to debug your applications.
To run the application in web mode, compile the application by running the KitchenSink-compile
script. The GWT compiler will generate a number of JavaScript and HTML files from the Kitchen Sink Java source code in the www/
subdirectory. To see the application, open the file www/com.google.gwt.sample.kitchensink.KitchenSink/KitchenSink.html
in your favorite web browser.
Since you've compiled the project, you're now running pure JavaScript and HTML that should work in IE, Firefox, or Safari. If you were to deploy the Kitchen Sink example project in production, you would distribute the files in your www/com.google.com.google.gwt.sample.kitchensink.KitchenSink/
directory to your web servers.
The source code for Kitchen Sink is in the src/
subdirectory. Try closing your browser windows, and open the file
src/com/google/gwt/sample/kitchensink/client/Info.java
in a text editor. Line 26 of the file is the first line of the
static initialization method for the first tab in the Kitchen Sink application ("Intro"):
return new SinkInfo("Intro", "<h2>Introduction to the Kitchen Sink.</h2>") {
Change the second string from "<h2>Introduction to the Kitchen Sink.</h2>"
to "<h2>Foo bar</h2>"
:
return new SinkInfo("Intro", "<h2>Foo bar</h2>") {
Now, save the file and simply click "Refresh" in the hosted mode application to see your recent change (if you previously closed
hosted mode, go ahead and re-run the KitchenSink-shell
script). The header should now say "Foo
bar" instead of "Introduction to the Kitchen Sink.":
GWT ships with a command line utility called applicationCreator
that automatically generates all the files you'll need in order to start a GWT project. It can also generate Eclipse project files and launch config files for easy hosted mode debugging, as described below.
Based on the recommended GWT project structure, your main GWT application class should be in a subpackage client
. You can create a new application called MyApplication with the command:
applicationCreator com.mycompany.client.MyApplication
The applicationCreator
script will generate a number of files in src/com/mycompany/
, including some basic "Hello, world" functionality in the class src/com/mycompany/client/MyApplication.java
. The script also generates a hosted mode launch script called MyApplication-shell
and a compilation script called MyApplication-compile
, just like the sample application above.
To run your newly created application in hosted mode, run the MyApplication-shell
script:
Try editing the files src/com/mycompany/client/MyApplication.java
and src/com/mycompany/public/MyApplication.html
to see how it changes your application.
GWT includes a command line utility called applicationCreator
that automatically generates all the files you'll need in order to start a GWT project. It can also generate Eclipse project files and launch config files for easy hosted mode debugging. To generate an Eclipse project for a new application, first use the projectCreator
script to generate a shell Eclipse project for your application:
projectCreator -eclipse MyProject
Then generate your GWT application as described above, but with an additional -eclipse
flag specifying the name of your Eclipse project:
applicationCreator -eclipse MyProject com.mycompany.client.MyApplication
When you're done with these scripts, in addition to the MyApplication-shell
and MyApplication-compile
scripts, you should see .project
, .classpath
, and MyApplication.launch
files in your current directory.
To open your project in Eclipse, launch Eclipse and click the File -> Import menu. Choose "Existing Projects into Workspace" in the first screen of the wizard, and enter the directory in which you genetrated the .project
file in the next screen of the wizard. When you are complete, you should see your GWT project loaded into your Eclipse workspace:
Just click the green "Run" button at the top of the window to start your project in hosted mode.