To develop programs using the GWT we need to first download it from here : GWT download.
Once you have it installed the next step would be to update the PATH environmental variable. For example if you have installed GWT in you C: drive as C:gwt-windows-1.5.3 then append this path to the end of the PATH variable. Once this is done you are ready to create GWT projects.
[Note: You need JDK 1.5 or above to develop GWT projects. You also need an IDE to develop the GWT projects. We will use Eclipse IDE in this tutorial]
Creating an Eclipse GWT project
Once the installation part is over we can now jump onto creating a new GWT project. Lets create a project which shows the temprature of cities.
- Open windows command prompt and navigate to the GWT installation directory. For e.g: C:gwt-windows-1.5.3>
- Create a directory by using the following command in current path:
- Change your current working directory to the directory we just created by using the following command:
After executing this command you should be at this location :
- Next type the following command in the current path:
projectCreator -eclipse TempratureWatch -out TempratureWatch
After executing this command, a directory by the name TempratureWatch is created. Inside the directoty we see the following directory and files :
- src – directory for storing the project source code
- test – directory for storing unit testcase
- .classpath – file used by Eclipse
- .project – file used by Eclipse
Next execute the following command :
applicationCreator -eclipse TempratureWatch -out TempratureWatch com.google.gwt.sample.tempraturewatch.client.TempratureWatch
This command creates a package structure as specified in the command line and creates a java class called TempratureWatch.java which would be the application’s entry point. The package structure chosen is as per GWT naming conventions. The entry point class must always be inside the client directory. The command also create an XML document called TempratureWatch.gwt at this location com.google.gwt.sample.tempraturewatch. This file will hold configuration settings for the GWT application.
Importing the project to Eclipse
Once you have the project directories created by using the commands explained in the last section the next step would be import the project to Eclipse. This can be done by using the following steps :
- Start Eclipse, then select File -> Import
- Select the project root directory by selecting: General -> Existing Projects into Workspace
- Select directory of the project. In our example we should choose: C:gwt-windows-1.5.3TempratureWatch
- Click Finish
Once done, you should be able to see the imported project in the Eclipse workspace. To run the application in hosted mode select the project and select the Run option under the Run menu. If the program starts successfully then you should be able to see a sample page which is created by default when you create a GWT project.
Difference between Hosted mode and Web mode
There are two possible ways by which we can execute our GWT project:
- Hosted mode
- Web mode
The way we started our application in the last section was the Hosted mode execution. In hosted mode the application is converted to bytecode and executed by the JVM (very much like java). This allows us to take advantage of the Java language API. In addition to this the hosted mode also allows us to debug application easily.