My favorites | English | Sign in

Google Web Toolkit

Getting Started - Quick Start

Installing Google Web Toolkit

Installing with Eclipse

If you use the Eclipse IDE, you can use the Google Plugin for Eclipse to install Google Web Toolkit. After restarting Eclipse you can create a new GWT application.

Installing without Eclipse

  1. If you don't already have it, install the Java SDK.
  2. Note for Mac users: GWT's hosted mode uses 32-bit SWT bindings, and requires a 32-bit JVM. To use GWT hosted mode on OS X 10.5 (Leopard) you need to use Java 5, as Java 6 on Leopard uses a 64-bit JVM. OS X 10.6 (Snow Leopard) includes 32-bit and 64-bit versions of Java 6. To force the 32-bit version to be used, include the -d32 flag on the command line when invoking the Java runtime. You can read more about the 32-bit requirement on this FAQ.

  3. If you don't already have it, download and unzip Apache Ant.
  4. Download and unzip Google Web Toolkit.
    On Windows, extract the files from the compressed folder gwt-windows-1.7.1.zip (or use a program like WinZip). On Mac or Linux, you can unpack the package with a command like
    tar zxvf gwt-mac-1.7.1.tar.gz
  5. GWT doesn't have an installer application. All the files you need to run and use GWT are located in the extracted directory. The main application you'll need to use GWT is webAppCreator, which is described below. It may be easiest to start out by building one of the sample applications shipped with GWT.

    Building a Sample Application

    All the sample applications are in the samples/ directory in your GWT package. Each sample has an Ant build script build.xml you can run to start it in hosted mode or compile it into JavaScript and HTML to run it web mode.

    Running in Hosted Mode

    To run the Mail sample in hosted mode, navigate to the samples/Mail/ directory and execute:

    ant hosted

    This executes the "hosted" Ant target in samples/Mail/build.xml, which opens the GWT browser with the Mail application running inside:

    Screenshot

    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.

    Running in Web Mode

    To run the application in web mode, compile the application by executing

    ant build

    The "build" Ant target invokes the GWT compiler which generates a number of JavaScript and HTML files from the Mail Java source code in the samples/Mail/war/ subdirectory. To see the application, open the file samples/Mail/war/Mail.html in your favorite web browser.

    Screenshot

    Since you've compiled the project, you're now running pure JavaScript and HTML that should work in IE, Firefox, Safari, or Opera. If you were to deploy the Mail example project in production, you would distribute the files in your samples/Mail/war/ directory to your web servers.

    Make a Few Changes

    The source code for Mail is in the samples/Mail/src/ subdirectory. Try closing your browser windows, and open the file samples/Mail/src/com/google/gwt/sample/mail/client/Shortcuts.java in a text editor. Line 54 of the file is the line that constructs the "Mail" tab.

    add(images, new Mailboxes(images), images.mailgroup(), "Mail");

    Change the final argument from "Mail" to "My Mail":

    add(images, new Mailboxes(images), images.mailgroup(), "My Mail");

    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 ant hosted). The first tab should now say "My Mail" instead of "Mail":

    Screenshot

    Creating an Application from Scratch (without Eclipse)

    GWT ships with a command line utility called webAppCreator that automatically generates all the files you'll need in order to start a GWT project. It also generates Eclipse project files and launch config files for easy hosted mode debugging, as described below.

    You can create a new application called MyApplication with the command:

    webAppCreator -out MyApplication com.mycompany.MyApplication

    The webAppCreator script will generate a number of files in MyApplication/, including some basic "Hello, world" functionality in the class MyApplication/src/com/mycompany/client/MyApplication.java. The script also generates an Ant build script MyApplication/build.xml, just like the sample application above.

    To run your newly created application in hosted mode, change to the MyApplication/ directory and execute:

    ant hosted

    Screenshot

    Try editing the files MyApplication/src/com/mycompany/client/MyApplication.java and MyApplication/war/MyApplication.html to see how it changes your application.

    Creating an Application from Scratch (with Eclipse)

    Using the plugin

    The Google Plugin for Eclipse contains a wizard for creating GWT applications. After installing the plugin and restarting Eclipse, here are steps for creating a starter application.

    1. In the toolbar, click the New Web Application Project button icon.
    2. Fill out the project details:
      1. Enter the project name "MyApplication".
      2. Enter the package "com.mycompany".
      3. Make sure Use Google Web Toolkit is checked and that Use default SDK (GWT) is selected.
      4. (Optional) If you are using Google App Engine, make sure Use Google App Engine is checked and that Use default SDK (App Engine) is selected.
      5. If you did not install the SDKs when you installed the Google Plugin for Eclipse, you should click Configure SDKs... to specify the directory where GWT (and the App Engine SDK) was unzipped.
    3. Click the Finish button.

    Without using the plugin

    If you do not want to use the Google Plugin for Eclipse, you can import a project created with webAppCreator as described above. To open your project in Eclipse,

    1. From the File menu, select the Import... menu option.
    2. Select the import source General > Existing Projects into Workspace. Click the Next button.
    3. For the root directory, browse to and select the MyApplication directory created by webAppCreator. Click the Finish button.

    You should see your GWT project loaded into your Eclipse workspace:

    Screenshot

    Just click the green "Run" button at the top of the window to start your project in hosted mode.