Friday, March 2, 2007

Configuring GWT as a Eclipse web-project


I didn't find how to install GWT into eclipse. Finally I find a possible approach which i docmented as follows. May b its helpful, if not , feel free to get in touch with me.In this example i would create an application which finally makes an async call to server and fetches the time from there.

To the end we should be able to debug inline with eclipse editor. Here i use my-eclipse i think it works even with eclipse editor also. Its a simple applicatoin.

By the way, whats GWT? and documentation etc, i leave it to the home site of gwt.

now by project creator,

create a web project, uncheck the default location, as below, and locate the sourece folder.

u should see the following in the navigator of eclipse

now the scene starts, when u run the gwt, in standalone mode, it creates www, bin folders and does the processings, but now need to make it create WebRoot and WebRoot/classes and use them instead. This requires editing of cmd files and here we go!

open compile cmd file as follows

@java -cp "%~dp0\src;%~dp0\bin;D:/r/work/UI/gwt-windows-1.3.3/gwt-user.jar;D:/r/work/UI/gwt-windows-1.3.3/gwt-dev-windows.jar" -out "%~dp0\www" %* com.ui.clock

is what u see, now change

bin -> WebRoot\WEB-INF\classes
www -> WebRoot

To check if rpc is also working proceesd as follows:

create a new class as

create the following interface

package com.ui.client;

public interface ClockInt extends RemoteService{

String getDate();


create the async interface as follows

package com.ui.client;

public interface ClockIntAsync {


The IDE may throw errors, for it u need to import the 3 jar files in gwt.xip that you have downloaded from the GWT home page and include them in eclipse properties (how? right click on project select properties, click on java build path, click on libraries tab, add external jars, and navigate to the gwt-windows 1.3.3 -could be found when u unzip the gwt-windows 1.3.3 zip file from gwt home page. Select all the three jar files.)

The errors now disappear, if still not refresh the project.

Create the server side implimentation to the ClockInt as follows:

1. create the folder server at this results in com.ui.server package.

write the folloing code in the package

package com.ui.server;
import java.util.Date;
import com.ui.client.ClockInt;

public class ClassImpl extends RemoteServiceServlet implements ClockInt {
public String getDate() {
Date today =
new Date();
return today.toLocaleString();

update the clock.gwt.xml file as follows

<inherits name=''/>

<entry-point class='com.ui.client.clock'/>
<servlet path="/Clock.rpc" class="com.ui.server.ClockImpl" />

Hey! dont worry, we are to the end.

public class clock implements EntryPoint {

public void onModuleLoad() {
final Button button = new Button("Click me again");
final Label label = new Label();
ClockIntAsync clockAsync = (ClockIntAsync) GWT.create(ClockInt.
ServiceDefTarget endPoint = (ServiceDefTarget) clockAsync;

AsyncCallback asyncCallBack =
new AsyncCallback() {
public void onSuccess(Object result) {
new HTML(result.toString()));

public void onFailure(Throwable ex) {
new HTML(ex.toString()));

button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if (label.getText().equals(""))
"Hello World!");

Test the configuration in stand alone mode. Click on clock-compile.bat and then on clock-shell.bat successively. You should see the clock displayd to the bottom of page.

To deploy to webservr:

Make these entries:









Things are ready and deolpy the project onto tomcat server as exploed archive. Start the server, and try with this url:
URL: http://localhost:8080/Clock/com.ui.clock/clock.html

u should see the same clock as u saw in stand alone mode. Thats it.


No comments:

Post a Comment