ClassNotFoundException: com.google.gwt.core.client.GWTBridge

This post will explain the cause of this exception and provide an easy fix – with no need to add extra jars to your classpath or manually manipulate your jars.

I first saw this exception when I upgraded a project from GWT 2.4 to GWT 2.5.

The project also uses GXT 2 and 3 running side by side.

After the upgrade I saw this in the logs:

…………..

Caused by: java.lang.NoClassDefFoundError: com/google/gwt/core/client/GWTBridge
at com.extjs.gxt.ui.client.core.FastMap.<init>(FastMap.java:139)
at com.extjs.gxt.ui.client.data.RpcMap.<init>(RpcMap.java:69)
at com.extjs.gxt.ui.client.data.BaseModelData.set(BaseModelData.java:125)
at com.extjs.gxt.ui.client.data.BaseModel.set(BaseModel.java:143)
…………..

TL;DR version:

Add the below  in your project (make sure the package is right):

package com.google.gwt.core.client;
import com.google.gwt.core.shared.*;

/**
* Date: 1/17/13
* Time: 12:37 PM
* This class is used for fixing class not found com.google.gwt.core.client.GWTBridge;
*
* This is only needed for GXT 2 to work. Once we remove GXT2, this can be removed also.
*/
public abstract class GWTBridge extends com.google.gwt.core.shared.GWTBridge {
}

Long version:

This is the issue in which Google is tracking this: http://code.google.com/p/google-web-toolkit/issues/detail?id=7527
Status is: fixed, not released. It will be released in 2.5.1 it seems.

FastMap class from GXT2 uses GWT.isScript() method to figure out if it’s running in a JS form, or a Java-translated form.

The issue is that GWT class from the client package, has a method called:  setBridge, with a GWTBridge as a parameter, but no import.

So the classloader searches for GWTBridge, inside com.google.gwt.core.client, but there is no class there.
This is the GWT class from 2.5.0:  http://google-web-toolkit.googlecode.com/svn/tags/2.5.0/user/src/com/google/gwt/core/client/GWT.java

The fix just adds it in the package in which the classloader is looking. As you can see it doesn’t change it in any way.

Hope this helps.

Regards,

Alex.