Run gwtXP examples in Eclipse
Posted in Eclipse, gwtXP on December 5th, 2009 – 9 CommentsI received some emails asking how to setup and run gwtXP examples in IDEs.
This post shows how to do it in Eclipse. I recommend to use Google Plugin for Eclipse during developing GWT applications.
Create a Hello project
In your Eclipse IDE, select File – New

- Type in the project name and the package
- Select “Use Google Web Toolkit” check box and click Finish button.

Configure project’s Run/Debug settings
- Open project properties dialog: Right-click on Hello project and select Properties from pop-up menu
- Go to Run/Debug Settings section
- Click on the “Hello” launch configuration and click Edit button
- In the Edit Configuration dialog, click on Arguments tab and change the Working directory option from “Other” to “Default”

- Click OK
- Go to Java Build Path section, click on “Add External JARs” and select the gwtXP.jar you downloaded from http://www.gdevelop.com/w/downloads/
- Click OK
Create new EntryPoint class
Create a new class HelloGwtXP in com.gdevelop.samples.hello.client package as below
package com.gdevelop.samples.hello.client;
import com.gdevelop.gwtxp.client.GwtXP;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import java.util.Map;
public class HelloGwtXP implements EntryPoint{
private static Map gwtxpMap = (Map)GWT.create(GwtXP.class);
public HelloGwtXP() {
}
public void onModuleLoad() {
GwtXP gwtXP = gwtxpMap.get("com.gdevelop.samples.hello.client.Hello.gwtxp.xml");
RootPanel.get().add((Widget)gwtXP.getGUI());
}
}
Modify the Hello.gwt.xml
Open file Hello.gwt.xml, add a line to inherit the GwtXP module
<!-- Other module inherits --> <inherits name='com.gdevelop.gwtxp.GwtXP'/>
To use new created EntryPoint class, change the line
<entry-point class='com.gdevelop.samples.hello.client.Hello'/>
to
<entry-point class='com.gdevelop.samples.hello.client.HelloGwtXP'/>
Constants
For demo purpose, we create a new interface and a properties file as below
package com.gdevelop.samples.hello.client;
import com.google.gwt.i18n.client.Constants;
public interface HelloConstants extends Constants{
String greeting();
}
# HelloConstants.properties greeting=Hello
Controller class
Create a new class also in com.gdevelop.samples.hello.client package
package com.gdevelop.samples.hello.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
public class HelloController {
private static final HelloConstants constants =
(HelloConstants)GWT.create(HelloConstants.class);
private transient PropertyChangeSupport changeSupport =
new PropertyChangeSupport(this);
private String name;
public HelloController() {
}
/* =========== For property change event =========== */
public void addPropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
public void addPropertyChangeListener(String propName,
PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(propName, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(listener);
}
public void removePropertyChangeListener(String propName,
PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(propName, listener);
}
public HelloConstants getConstants(){
return constants;
}
public void sayGreeting(){
Window.alert(constants.greeting() + " " + (name != null ? name : "gwtXP"));
}
public String getName() {
return this.name;
}
public void setName(String name) {
String oldName = this.name;
this.name = name;
changeSupport.firePropertyChange("name", oldName, name);
}
}
For demo purpose, the controller class has a property ‘name’ which will be bound to a TextBox in next section.
For data binding, the controller class also has addPropertyChangeListener and removePropertyChangeListener methods.
The View
Create a new Hello.gwtxp.xml file. This file should reside in com.gdevelop.samples.hello.client too.
<?xml version="1.0" encoding="UTF-8" ?>
<g:gwtxp xmlns:g="http://www.gdevelop.com/gwtxp"
controllerClassName="com.gdevelop.samples.hello.client.HelloController">
<g:verticalPanel width="100%">
<g:textBox text="${name}" enabled="true"/>
<g:button text="${constants.greeting}" onClick="#{sayGreeting}"/>
</g:verticalPanel>
</g:gwtxp>
Running the example
Click the Run button in Eclipse toolbar to run the Hello example in HostedMode.
Check whether gwtXP works
In the HostedMode window, check to make sure there are no errors while gwtXP translate the Hello.gwtxp.xml to Java code.

The screen shot showing gwtXP’s logging information in the HostedMode log tree.
In the Hosted Browser window, type a name in the TextBox and click Hello button. You should see a greetings dialog box.
Important note
Recall the sayGreeting method in HelloController class.
public void sayGreeting(){
Window.alert(constants.greeting() + " " + (name != null ? name : "gwtXP"));
}
It does not have to the TextBox to get the name you typed in. Instead, the data binding take care of synchronization from TextBox to property.
Leave a Comment »


Hi, i have done as steps above. But when I run app, there is error as below
[ERROR] Unable to load module entry point class com.gdevelop.samples.hello.client.HelloGwtXP (see associated exception for details)
java.lang.NullPointerException: null
at com.gdevelop.samples.hello.client.HelloGwtXP.onModuleLoad(HelloGwtXP.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:326)
at com.google.gwt.dev.shell.BrowserWidget.attachModuleSpace(BrowserWidget.java:343)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6.access$300(BrowserWidgetIE6.java:37)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.gwtOnLoad(BrowserWidgetIE6.java:77)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.invoke(BrowserWidgetIE6.java:161)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:264)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:557)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
Anyone can help me to solve this problem ?
Hi,
In the post, there is a screen shot showing gwtXP’s logging information in the HostedMode log tree.
Check your HostedMode window if there is a line
“Generate code for file src/com/gdevelop/samples/hello/client/Hello.gwtxp.xml”
If not, change the project launch configuration to ensure the Working directory option is the “Default”, e.g the working directory should be the Hello directory not Hello/war.
See section “Configure project’s Run/Debug settings” in the post.
Hope this help
i have solved the problem.
Thanks,
I encounterd difficulties reading your site with google chrome, you have to update your site
I’m having a little bit of trouble viewing your site in Opera, but it may just be my computer. Apart from that, I love your site. I plan on browsing around and reading some more posts!
Hi, i have done as steps above. But when I run app, there is error as below
[ERROR] Unable to load module entry point class com.gdevelop.samples.hello.client.HelloGwtXP (see associated exception for details)
java.lang.NullPointerException: null
at com.gdevelop.samples.hello.client.HelloGwtXP.onModuleLoad(HelloGwtXP.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:326)
at com.google.gwt.dev.shell.BrowserWidget.attachModuleSpace(BrowserWidget.java:343)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6.access$300(BrowserWidgetIE6.java:37)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.gwtOnLoad(BrowserWidgetIE6.java:77)
at com.google.gwt.dev.shell.ie.BrowserWidgetIE6$External.invoke(BrowserWidgetIE6.java:161)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:264)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:557)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
Anyone can help me to solve this problem ?
Hi,
In the post, there is a screen shot showing gwtXP’s logging information in the HostedMode log tree.
Check your HostedMode window if there is a line
“Generate code for file src/com/gdevelop/samples/hello/client/Hello.gwtxp.xml”
If not, change the project launch configuration to ensure the Working directory option is the “Default”, e.g the working directory should be the Hello directory not Hello/war.
See section “Configure project’s Run/Debug settings” in the post.
Hope this help
Hi,
In the post, there is a screen shot showing gwtXP’s logging information in the HostedMode log tree.
Check your HostedMode window if there is a line
“Generate code for file src/com/gdevelop/samples/hello/client/Hello.gwtxp.xml”
If not, change the project launch configuration to ensure the Working directory option is the “Default”, e.g the working directory should be the Hello directory not Hello/war.
See section “Configure project’s Run/Debug settings” in the post.
Hope this help
Hi,
In the post, there is a screen shot showing gwtXP’s logging information in the HostedMode log tree.
Check your HostedMode window if there is a line
“Generate code for file src/com/gdevelop/samples/hello/client/Hello.gwtxp.xml”
If not, change the project launch configuration to ensure the Working directory option is the “Default”, e.g the working directory should be the Hello directory not Hello/war.
See section “Configure project’s Run/Debug settings” in the post.
Hope this help