Adding GWT to an Eclipse Web Project.
Continued from building-web-application-in-eclipseThis article builds on my previous posting on building a web application in Eclipse, which reached the point of demonstrating TDD (test driven development).
We start by adding GWT (Google Web Toolkit) to the basic web application which does not contain dynamic content and is configured to show only a simple index.html page. Our goal is to add GWT.
Audience: Developers with some background in GWT who want an overview of adding GWT capability to an existing web project. Nothing fancy.
Install GWT Plugin
In Eclipse, under Help->Install New Software, add the link to the GWT plugin and install. We're using GWT 2.4 in this article.Configure Project For GWT
Right click on the project name, and select Properties->Google. Configure war directory as /target/car-0.0.1-SNAPSHOT. Enable the project to use Google Web Toolkit.Create a new GWT Module
Select new->Other... Select Google Web Toolkit. Select Module. Go to 'next' step. Enter com.car for package. Enter "CarApp" for module name.Your project should now look like this:
Create an Entry Point Class
Select new->Other... Select Google Web Toolkit. Select 'Entry Point Class'. We provide the name "CarAppEntryPoint"Perform GWT Compile
Right click on project, select Google->GWT Compile. Add the entry point module we created in the previous step.The compile will produce GWT artifacts in the exploded war folder. In order for the entry point module to be executed, it must be referenced from the index.html page.
The script tag in the index.html file will look like this:
<script type="text/javascript" language="javascript" src="com.car.CarApp/com.car.CarApp.nocache.js"></script>
Just to satisfy ourselves that GWT is working, add a demo Label output to the page. Our entry point class will look like this:
package com.car.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class CarAppEntryPoint implements EntryPoint {
public void onModuleLoad() {
RootPanel.get("mainContainer").add(new Label("Hello There !"));
}
}
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class CarAppEntryPoint implements EntryPoint {
public void onModuleLoad() {
RootPanel.get("mainContainer").add(new Label("Hello There !"));
}
}
Add GWT to pom.xml
This example uses GWT 2.4.0. Maven must have GWT dependency configured, or the compile will fail. Note that so far, Maven does not compile GWT into javascript. So far, we are still depending on a separate GWT compile.<dependency>
<groupid>com.google.gwt</groupid>
<artifactid>gwt-servlet</dependency>/artifactid>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupid>com.google.gwt</groupid>
<artifactid>gwt-user</artifactid>
<version>2.4.0</version>
<scope>provided</scope>
</dependency>