Apr 25

The first time I heard about Google Web Toolkit, I was excited. I immediately downloaded it; wrote few samples and found that it was really a nice piece of software. But it lacked one thing - IDE integration. Although “GWT was intentionally designed to work well in any IDE”, there was no direct support for GWT in any IDE. I thought how about writing an Eclipse plugin for that? I’m not an Eclipse plugin developer. I was a pure C++ guy who has jumped into several layers of J2EE and .NET and settled as a mainline developer in a top SOA product. Eclipse plugin development is something I’ve to learn. I decided to give a try.

Result? Googlipse. That is my first plugin. With over 25,000 downloads and counting, it generated a good amount of interest. So I get bugs (yeah, sometimes I write embarrassing code) and people extend it. It was a wonderful experience in learning Eclipse and gave me a better understanding about the Open Source from the contributing perspective. Googlipse has shifted my career and now my day job is also plugin development. Besides all this, I’ve to kill Googlipse. Why? Because of the name!

I was over enthusiastic that I coined the name by joining two names: Google+Eclipse. The logo is also the same way, Google colored text in an Eclipse background. I thought who cares about the name. I was wrong.

Google’s legal department had “some trademark concerns about the name”. I was pointed to Google Branding Guidelines. So I decided to change the name and logo. Hmmmm. That means its virtually creating a new product (at least to the users who don’t worry about the code!) That is what I’ve done now. I’ve created a brand new product called “Cypal Studio for GWT“. It is hosted @ Google Code. Its essentially the same code base (with the same Apache 2.0 license) but with little changes and few bug fixes.

So what happens to Googlipse now? Its dead. Means there will be no more bug fixes, no more features. The existing downloads & code base will remain there @ SourceForge. The home page will be soon pointing to new product’s site (which is under development). Thus ends the story of my first Eclipse Plugin.

written by Prakash G.R.

Jan 15

Nominated Googlipse for Eclipse Foundation Awards.

Let me cross my fingers and wait for March 5th for the results to be announced at the EclipseCon 2007.

[Update: 23 Jan 2007]

The list of accepted nominations is huge with big players like Hibernate tools, Aptna IDE, Subclipse, etc. Its now too hard for a product like Googlipse (which is not even version 1 and focuses on a small community). Lets see …

written by Prakash G.R.

Dec 28

I was searching for something on GWT recently. Didn’t find it. I thought there must be some FAQ on GWT. Unfortunately, there is nothing. I thought I’ll create one. As of now the basic site is up (Thanks to Google Creator, its all done in less than an hour, without touching any HTML or spending a single paise), I’ve to collect questions and update the site with proper answers. If you have any questions to be added, do send it to me. (prefeably with answers)

written by Prakash G.R.

Dec 14

An awesome move by Google - whole of GWT is now opensourced. GWT’s user library was already opensourced with Apache license, but now the Java to Javascript compiler is also open sourced. The good thing is that they are accepting patches so you can submit your code to Google and become a committer as well.

Good work Google :-)

written by Prakash G.R.

Oct 12

A better and updated version is maintained here (http://grprakash.googlepages.com/gwtwithejb).
In this post, I thought I’ll explain how to use GWT with EJB. GWT addresses the web layer and EJB the middle layer, its natural to use both of them to have a neat J2ee app.

I assume that you know how to create EJB project and Web project with Googlipse. For the second one, I’ve written a post here.

If you are an advanced EJB developer and have used GWT for a while, “Use the RemoteServiceImpl as a EJB client and continue in the as usual way”. If you are not, then the rest of the post is for you.

What we are trying now is to have a text box in the web page and a button. When you key in a person’s name there and press the button, it will show the age of the person.

The first step is to create a Stateless Session Bean. The Remote & Home interface will look like this:

public interface AgeServiceEjb
extends EJBObject, Remote {

public int getAge(String name);
}

public interface AgeServiceHome
extends EJBHome {
public AgeService create()
throws …;
}

The EJB looks something like:

public class AgeServiceBean
implements SessionBean {

//All EJB members here
public int getAge(String name){

int age;

if(name.equals(”Pranni”))
age = 18; //Pranni is always 18 :-) else if(name.equals(”Bill Gates”))
age = 51;
else
age = 40; // default value

return age;
}
}

I opted for a very simple implementation. Of course you have do the normal way of contacting the Data Layer. Use Entity beans or try plain JDBC or use Hibernate. Check whether name is null or not, throw a NameNotFound exception. Its the plain old normal EJB code. GWT never restricts anything here. If you already have some EJB, exposing it to a servlet or a swing client, very well, you can reuse that also.

Now let us create a Remote service in the Web layer.

The GWT’s RemoteService is very similar to the RemoteInterface of EJB:

public interface AgeServiceGwt
extends RemoteService {

public int getAge(String name);

// Other members Util, SERVICE_URI etc
}

The RemoteService’s Impl is the key which connects GWT and EJB:

public interface AgeServiceGwtImpl
extends RemoteServiceServlet
implements AgeServiceGwt{

public int getAge(String name){
Context ctx = new InitialContext();
AgeServiceHome hme =
(AgeServiceHome)ctx.lookup(”<JNDI name>”);
AgeServiceEjb ageService = hme.create();
return ageService.getAge(name);
}
}

You can do all the normal EJB client stuff here. Add parameters to create initial context, configure the JNDI name, cache the home interface, etc. If you have ever used JSP/servlets calling EJB code, think it in the same way. Treat the Impl class as a servlet (in fact it is!) and do the usual way.

Common problems:

  • How do I deploy the EJB in the GWT’s embedded Tomcat server?


You can’t. In fact you can’t deploy it even on an external Tomcat. Its just a web container. You need an app server like WebLogic or JBoss

  • How do I create a EAR file?


Create an EAR project and add these projects (EJB & Web) to it. Select File->Export->Export as EAR file

  • Can I deploy the application in an app server and still debug in hosted mode?


Yes. Look at “Deploying to an external server” in the GWT tutorial. Its the same way.

written by Prakash G.R.

Sep 05

[Update - A recent revision of this tutorial is available at here.

This tutorial introduces you to GWT. You can do develop GWT apps without any IDE, but it is really helpful if you use one. I choose Eclipse with a plugin for GWT called Googlipse to walk thru this tutorial. Not because Eclipse & Googlipse are free or because Eclipse is the default Java IDE for many developers, but simply because I’m the creator of the Googlipse plugin :-P

Requirements:

  • You need the latest GWT. You can download it at here. Make sure you download the latest version.
  • Download and install Eclipse 3.2 with WTP 1.5. You can get it here.
  • You need a Java 1.5 VM to run Googlipse. You can get it here.
  • Download Googlipse from here and drop in the jar in your eclipse\plugins directory.

Settings:

Before you start, you need to tell Googlipse where you have installed GWT. In Eclipse, select Window -> Preferences -> Googlipse -> Browse. Select the directory where you have installed GWT.

Creating the App:

Create a new Dynamic Web Project. (File-> New -> Project -> Dynamic Web Project)

In the first Wizard page, type “Hello World App” for Project Name and select “Default Googlipse Project” in the Configurations drop down. Click Finish.

With GWT you organize your code as Modules. Modules are typically organized under a package. When you create a module, you will have

  • A <module name>.gwt.xml file, where you will have all your configurations of a module
  • A folder named “public”, where you will have all your html, css, images, etc
  • A package named “client”, where you will have all the client side code - which will be converted into JavaScript later
  • A package named “server”, where you will have all the server side code - in form of Servlets

Select File-> New -> Other -> GWT Module

You can select an existing package if you have already created, or create a package where you want to keep your module. Type “MyModule” for Name and click Finish. In the Package Explorer view, you can see that all the necessary code to run a module is created by Googlipse for you. Now you have the basic skeleton of a GWT app, lets run the app in hosted mode.

Running in Hosted Mode:

Googlipse integrates GWT hosted mode into Eclipse in a nice way. Select Run -> Run -> GWT Application. Click the “New Launch Configuration”. You can select the project and the module, which you want to run. In the parameters page, you can customize the options passed to GWTShell. Click Run. You should see two windows popping up. One is the GWT Shell and the other is the hosted browser. Click the ‘Click Me’ button in the browser window, and you can see the “Hello World!” message right next to the button.

Compiling the application to JavaScript:

You can compile the client code into JavaScript, so that you can deploy it on any standard WebServer. Click the “Compile/Browse” button in the hosted mode browser. This will compile create the javascript and other supporting files under the build\gwtOutput directory.

Deploying to an external server:

Open the Servers view (Window -> Show View -> Other View -> Server -> Servers). Configure your favourite WebServer in the view (Right click on the view -> New -> Server) You can configure any server (Weblogic, JBoss, Tomcat, etc) and the configuration depends on the vendor and its not described here. Assuming you have configured a server, say Weblogic 9.0 server. Right click the configured server -> Add and Remove Projects. In the dialog box, move our Hello World App from Available Projects to Configured Projects and click Finish. Now you can start the server and see your application @ http://localhost:7001/Hello_World_App/MyModule.html (The URL varies depending on the server vendor and the server configuration)

Creating a WAR file:

Creating a WAR file for deployment is very simple. Select File -> Export -> WAR file and follow the wizard.

Adding RemoteServices:

What we have done so far is a simple static application. There is no RPC involved. GWT supports a properitary mecahnism thru which the client code and server code communicate. The heart of the RPC is a RemoteService interface. This lies in the client package of the module. The implementation of this interface should be available in the server package. By convention, the class is named as <RemoteService>Impl and Googlipse enforces this. There is another interface called the Async interface. Async interface is based on the RemoteService interface. More details about this interface is available here. We don’t have to worry about this interface, because Googlipse create this Async interface for you and will maintain it.

Select File -> New -> Other -> Gwt Remote Interface to create a RemoteInterface. You need to select the module where it will reside and then give the name and uri. Uri is typically where the client will be looking for the the server code. It should be unique within the given application. Click Finish and you see the RemoteService and RemoteServiceAsync are created in the client package and the RemoteServiceImpl is created in the server package. The RemoteService interface also has an inner class Util with one method getInstance. This will be very handy for invoking the service from the client code. We will see this later. Now lets add a method in the interface:

String sayHello() throws Exception;

You can see Googlipse will update the Async interface with this method signature

 

void sayHello(AsyncCallback callback);

Basically it removes the return type and exceptions and adds the callback parameter at the end of the parameter list.

In the Impl class, implement this method

public String sayHello() throws Exception {
return “Hellooooooo”;
}

Invoking RemoteServices:

From the client code, you can use the getInstance method to invoke the RemoteService.

I’ve modified the MyModule.java to have an RPC call:

button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
MyServiceAsync instance = MyService.Util.getInstance();
instance.sayHello(new AsyncCallback(){

public void onFailure(Throwable error) {
Window.alert(”Error occured:”+error.toString());
}

public void onSuccess(Object retValue) {
Window.alert(”Server returned:”+retValue.toString());
}
});
}
});

As you can see, the onFailure method is called whenever there was any problem with the RPC call. If everything goes fine, onSuccess method is called with the return value from the method.

Common problems:

  • I installed Googlipse and nothing happened.

There are 2 possible reasons:

1) You are running an Eclipse 3.1 or earlier.

2) You are running Eclipse on a Java 1.4 VM or earlier

  • How do I change the URI of the application?

Right click the project -> Properties -> Web Project Settings. Change the Context Root value

  • I added the Googlipse facet to an existing Dynamic Web App. Nothing works.

Follow these steps for adding the Googlipse facet to an existing app:

    • First remove the gwt-user.jar from the application build path
    • Remove gwt-servlet.jar from WEB-INF\lib directory
    • Add the facet
    • Open .settings\org.eclipse.wst.common.component file and for every module in your application, add the line
    • <wb-resource deploy-path=”/” source-path=”/build/gwtOutput/com.googlipse.testApp.MyModule”/> where com.googlipse.testApp is the package and MyModule is Module name.
    • Refresh the application.
  • I upgraded from previous version of Googlipse. I’m getting some errors.

You have to uninstall the Googlipse facet and then follow the above steps to install the facet again.

 

written by Prakash G.R.

May 25

I’m trying out few samples with Google Web Toolkit. Its really nice to play with. I googled for a tutorial. Cudn’t find anything good. But I managed to find one small GWT tutorial ;-)

written by Prakash G.R.

May 18

No this is not a post about Google’s Calendar or Notebook. Its rather about the GWT - the Google Web Toolkit. Some time back I wrote an entry about Ajax and how hard it would be to maintain a code. Now to make developers life simple, Google has released their Ajax framework. This is the same framework that runs Gmail! At a first look it looks great. I’m going to try it out and give a detailed post later.

written by Prakash G.R.