Home arrow AJAX & Prototype arrow Installing Google Web Toolkit

Installing Google Web Toolkit

The Google Web toolkit is a useful open source toolkit that can be used by web developers for developing complex JavaScript applications/AJAX in Java. This article will show you how to get started using it.

  1. Installing Google Web Toolkit
  2. Run the Web Application in Development Mode
By: Codex-M
Rating: starstarstarstarstar / 2
September 27, 2010

print this article



In short, a developer using the toolkit will be using the Java programming language before compiling, and then test the web application in the development mode using tools offered by the Google web toolkit.

Once the development is done, the Java code is then compiled into pure JavaScript code, which can then be deployed on web servers and is compatible with most common browsers.

One advantage of using the Google web toolkit is that it makes writing AJAX and JavaScript applications as simple as possible.

This tutorial will focus on the use of the Google web toolkit in Ubuntu (Linux) and is primarily targeted at beginners.

Getting Started with Google Web Toolkit

You need to download the toolkit, which is available here: http://code.google.com/webtoolkit/download.html. Click the “Download SDK” button.

It will then be downloaded to the Ubuntu download folder. Right click on the zip file, and then click “Extract here.” Copy the folder (e.g gwt-2.0.4) to your Ubuntu desktop.

The best way to get started with the Google web toolkit is to create a web application using it. For the sake of simplicity, let's use the test web application illustrated here: http://code.google.com/webtoolkit/gettingstarted.html 

Note that the procedure is not quite specific, and you need to know all the steps in detail, including troubleshooting and terminal commands. So let's illustrate that in this tutorial completely.

Since your Google web toolkit is now located in your Ubuntu Desktop, open the terminal (Applications ==> Accessories ==> Terminal). Let's create a web application and name it MyWebApp

The commands are as follows:

codex-m@codex-m-desktop:~$ cd Desktop
codex-m@codex-m-desktop:~/Desktop$ cd gwt-2.0.4
codex-m@codex-m-desktop:~/Desktop/gwt-2.0.4$ chmod u+x webAppCreator
codex-m@codex-m-desktop:~/Desktop/gwt-2.0.4$ ./webAppCreator -out MyWebApp com.mycompany.mywebapp.MyWebApp

This app goes to the Ubuntu Desktop, and then changes the directory to gwt-2.0.4. The CHMOD u+x actually makes the webAppCreator executable; this is necessary to create the application.

If there is no problem, several files and directories will be created by the Google web toolkit.

Installation of Apache Ant as a Build Tool to Compile Java Code

The “getting started” guide for the Google web toolkit uses Ant (http://ant.apache.org/) as the build tool. However, before you can use Ant, you need to install it in Ubuntu. Follow the steps below:

  1. Go to the Synaptic Manager, and in the quick search, type ant.
  2. Click Ant, and then click “Mark for Installation.”
  3. Click “Mark” and then click “Apply” on the Synaptic Manager menu.
  4. When you see “Apply the following changes,” click “Apply.”

Now that it is completely installed, let's run the Google web toolkit development mode using Ant. Open the terminal, and then type the commands below (assuming you do not change your Google web toolkit directory and it is still found on the Desktop):

codex-m@codex-m-desktop:~$ cd Desktop
codex-m@codex-m-desktop:~/Desktop$ cd gwt-2.0.4
codex-m@codex-m-desktop:~/Desktop/gwt-2.0.4$ cd MyWebApp
codex-m@codex-m-desktop:~/Desktop/gwt-2.0.4/MyWebApp$ ant devmode

However, when you execute the ant devmode command, you might encounter an error such as the one below:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
Buildfile: build.xml
    [mkdir] Created dir: /home/codex-m/Desktop/gwt-2.0.4/MyWebApp/war/WEB-INF/classes
    [javac] Compiling 5 source files to /home/codex-m/Desktop/gwt-2.0.4/MyWebApp/war/WEB-INF/classes
/home/codex-m/Desktop/gwt-2.0.4/MyWebApp/build.xml:28: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"
Total time: 0 seconds

This is because the Openjdk-6-jdk (Open Java Development Kit) is still not installed and configured to work with the Google web toolkit.

Open the Java Development Kit for Google Web Tool Kit

To install the required Java development toolkit:

1. Go to the Synaptic manager, and in the quick search, type java-6-openjdk.

2. You need to click: openjdk-6-jdk

Screen shot:

3. Continue with the installation until it is successfully completed.

4. Go to Applications ==> Accessories ==> Search for files...

5. Under “Name contains:” type tools.jar. You need to know the updated JDK path of this file in your Ubuntu file system.

You should see results like this: usr/lib/jvm/java-6-openjdk/lib

This is the folder in your Ubuntu file system that contains the tools.jar file using the Open Java Development Kit. This means you have successfully installed openjdk.

When you look at the error in the previous section, it required pointing the JAVA_HOME to openjdk for the build to succeed.

You need to edit the bash.bashrc file in the Ubuntu etc directory. To do this, open up the terminal, and then type the following commands:

codex-m@codex-m-desktop:~$ sudo -s -H
root@codex-m-desktop:/home/codex-m# cd /
root@codex-m-desktop:/# cd etc
root@codex-m-desktop:/etc# pico bash.bashrc

Scroll down to the bottom of the file, and then add the following code:

export JAVA_HOME
export PATH

If the path that contains tools.jar (in the file search result previously) is: usr/lib/jvm/java-6-openjdk/lib

You should set JAVA_HOME to /usr/lib/jvm/java-6-openjdk

To confirm your new JAVA_HOME, enter this in terminal:

root@codex-m-desktop:/etc# echo $JAVA_HOME

It will check the new location of Java Home, so the result should be:
To confirm the path:

root@codex-m-desktop:/etc# echo $PATH

>>> More AJAX & Prototype Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Best AJAX Tutorials for Forms
- The Best AJAX Tutorials
- 8 Great Ajax Tutorials
- Using Ajax and jQuery
- Using Ajax and jQuery with HTML Forms
- Ajax.org Offers Cloud9 IDE for JavaScript
- Java Technologies Provider ICEsoft Releases ...
- Using Recaptcha in AJAX Prototype Framework ...
- Google's Closure Compiler Service API: Addit...
- Installing Google Web Toolkit: Introducing t...
- Google's Closure Compiler Service API: Displ...
- Google's Closure Compiler Service API: Deliv...
- Google's Closure Compiler Service API: the A...
- Google's Closure Compiler Service API: the S...
- Google's Closure Compiler Service API: Optim...

Developer Shed Affiliates


Dev Shed Tutorial Topics: