Tutorial: GWT, Maven and Eclipse with M2Eclipse
This tutorial shows how to develop Rich Internet applications with the Google Web Toolkit (GWT) using a state of the art Software Development Environment, especially Maven integrated in Eclipse through m2eclipse (There is another plugin IAM, but in this tutorial we will use M2Eclipse). We will set up the environment, create a web application that is using Google Maps and debug it. This tutorial is the Maven version of this one using Cypal Studio.
Preliminaries
First we have to download Java and Eclipse. We will not download the Google Web Toolkit, Cypal Studio or the Google Maps library for GWT like in my last tutorial.
- Download and install the Java SE Development Kit
You need the JDK to run Eclipse, the GWT Hosted Mode-Browser and the GWT-Compiler. On MacOS the JDK is installed by default, for other operating systems you can download the JDK from Sun. - Download and unzip the Eclipse IDE for Java EE Developers
Download Eclipse for EE Developers. You can unzip Eclipse to whereever you like, for example into the folder applications or programs. - Sign up for a Google Maps Api-Key (optional, only necessary for production use)
This step is optional for development on your local computer (localhost). You can sign up for a key here.
Setup the eclipse workspace and configure plugins
Configure the eclipse workspace and project. This section contains only the configuration of eclipse, no source code that you would check in for example into svn.
- Eclipse Workspace
Open Eclipse and choose a directory as workspace (project configuration and source code will/can be stored here).

When Eclipse has started, you will see the welcome screen:

Close the Welcome screen with the arrow on the right side and the workspace is displayed:

- Add the m2eclipse plugin (Integration of Maven into Eclipse)
Open Help/Install New Software… and click Add on the upper right side:

Enter M2Eclipse as name, http://m2eclipse.sonatype.org/update/ as Location and click OK:

Select the items shown and click Next:

Review the details and click Next:

Accept the license and click Finish:

Wait until the download has finished and the installation is complete and restart Eclipse (click yes).
Your first GWT application with Maven and Eclipse
Now we will create a simple GWT application based on an archetype.
- Create a Maven project
Select File/New/Other… , select Maven project and click Next:

Click Next:

Select the gwt-maven-plugin archetype from org.codehaus.mojo and click Next:

Enter Maven details for this project and click Finish:

Your workspace will look like this:

- Edit the pom.xml
This is the Project Object Model – maven project configuration file. Change the version of GWT to 1.7.o<gwt.version>1.7.0</gwt.version>
Add the following dependency to the dependencies:
<dependency> <groupId>com.google.gwt.google-apis</groupId> <artifactId>gwt-maps</artifactId> <scope>provided</scope> <version>1.0.4</version> </dependency>
Add the following line direct below the gwt.version-tag within the properties:
<runTarget>com.claudiushauptmann.gwt.maven.sample.Application/Application.html</runTarget>
Change the plugin version to 1.1:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <goals> <goal>compile</goal> <goal>generateAsync</goal> <goal>test</goal> </goals> </execution> </executions> </plugin>
- Edit the Application.gwt.xml
This is the gwt module descriptor. We have to tell it, that we are using the Google Maps library (Yes, we have to do this twice. One time for Java and on time for GWT, because GWT should not use all Java libraries). Add the following lines:<script src="http://maps.google.com/maps?gwt=1&file=api&v=2" /> <inherits name="com.google.gwt.maps.GoogleMaps">
- Edit the entrypoint (Application.java)
This is the code that will be executed when the site is openend:package com.claudiushauptmann.gwt.maven.sample.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.maps.client.MapWidget; import com.google.gwt.maps.client.control.MapTypeControl; import com.google.gwt.maps.client.control.SmallMapControl; import com.google.gwt.maps.client.event.MapClickHandler; import com.google.gwt.maps.client.geom.LatLng; import com.google.gwt.maps.client.overlay.Marker; import com.google.gwt.maps.client.overlay.Overlay; import com.google.gwt.user.client.ui.RootPanel; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class Application implements EntryPoint { /** * This is the entry point method. */ public void onModuleLoad() { MapWidget mapWiget = new MapWidget(LatLng.newInstance(48.136559, 11.576318), 13); mapWiget.setSize("500px", "300px"); mapWiget.addControl(new SmallMapControl()); mapWiget.addControl(new MapTypeControl()); mapWiget.addMapClickHandler(new MapClickHandler() { public void onClick(MapClickEvent e) { MapWidget sender = e.getSender(); Overlay overlay = e.getOverlay(); LatLng point = e.getLatLng(); if (overlay != null && overlay instanceof Marker) { sender.removeOverlay(overlay); } else { sender.addOverlay(new Marker(point)); } } }); RootPanel.get().add(mapWiget);</pre> } <pre>}
Building the project
The build will be run automatically when debugging the project.
- Select your project in the Project Explorer.
- Click Run/Run As/Maven install.
Debugging the project
Of course, you can use a plugin like Cypal Studio or the Google plugin for Eclipse. This is a way that works stable on Mac, Linux and Windows.
- Select your project in the Project Explorer.
- Select Run/Run As/Maven build…
- Type gwt:debug as goal, give your launch configuration a name and click Run:

- Select your project in the Project Explorer.
- Select Run/Debug configurations.
- Select Remote Java Application in the list on the left side and click the new launch configuration symbol on the upper left side and click Debug:

- The hosted mode browser will open and every time you click on the map a marker will appear:


Thank you for reading my tutorial! Please leave a comment and/or make a link from your web site.
25 Comments »
RSS feed for comments on this post. TrackBack URL
Thanks for the tutorial.
I use Eclipse Galileo 64 bit and trying to use GWT I get the error “…wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)…”
Is there any way round to this other than using 32 bit both jdk and eclipse?
Hi Pablo!
You could run GWT within Eclipse Galileo 64bit and then Google Plugin for Eclipse to figure out whether it is a GWT specific problem or it’s Eclipse/your jdk.
Perhaps it is possible to run your Eclipse 64bit and the GWT compiler and Hosted Mode Browser inside a 32bit jdk?
Please leave a comment if you find a solution.
Hi there,
When i try to debug the project (step 6 in Debugging the project). I got an error message “Failed to connect to remote VM” . Can you help me with this?
Thanks
Hi Zephyr, please paste some log message from step 3.
I’m having problem pasting the log msgs here, cause I get a blank screen after i clicked the submit comment button
11/01/10 5:09:33 PM: [INFO] User settings file does not exist C:\Users\acer\.m2\settings.xml
11/01/10 5:09:34 PM: Eclipse is running in a JRE, but a JDK is required
Some Maven plugins may not work when importing projects or updating source folders.
11/01/10 5:09:42 PM: Updating index http://repo1.maven.org/maven2/
11/01/10 5:09:45 PM: Downloading central : nexus-maven-repository-index.properties
11/01/10 5:09:45 PM: Downloaded [central] -> http://repo1.maven.org/maven2/.index/nexus-maven-repository-index.properties
11/01/10 5:09:45 PM: Updated index for http://repo1.maven.org/maven2/ Sat Jan 09 17:50:45 SGT 2010
11/01/10 5:11:06 PM: Creating new launch configuration
11/01/10 5:11:51 PM: E:\Eclipse\my-first-gwt-project-with-maven
11/01/10 5:11:51 PM: Build type none : gwt:debug
11/01/10 5:11:51 PM: mvn -B -s C:\Users\acer\.m2\settings.xml gwt:debug
11/01/10 5:11:51 PM: Build type none : gwt:debug
========================================================
Sorry for the hassle
The details of problem is – “Failed to connect to remote VM. Network is unreachable: connect”
========================================================
Succeeded after breaking the post in few parts
You should receive the following log messages in step 3 (mvn gwt:debug), otherwise you will not be able to connect in step 6:
[INFO] Listening for transport dt_socket at address: 8000
so you mean, I should get mvn: gwt:debug instead of Build type none: gwt:debug ?
Does it have to do with Eclipse is running on a JRE but JDK? However I got my JDK installed at drive D same with Eclipse and JRE at drive C.
Hi Zephyr, since I’m using a Mac I cannot test the differences between JDK und JRE, because there is a JDK preinstalled and no JRE available.
The correct command without m2eclipse is “mvn gwt:debug”, so you should enter gwt:debug in step 3.
yup, i entered gwt:debug in step 3 but still the same problem occurred.
Is tomcat needed? cause I don’t have Tomcat installed.
how to import an exiting maven project into eclipse? i want use the debug?
hi,
how could i use development mode with eclipse, mvn and ejbs deployed on jboss server? Is there any way to tell dev mode rpc-s that use ejbs to know where the ejbs are deployed?
Thanks for publishing the above. Here’s a couple of typos and a question.
tep 2:
* Reads: …1.7.o
** Should read: …1.7.0
(but see question below)
Step 3:
* Reads: One time for Java and on time for GWT, because GWT should not use all Java libraries
** Should read: Once for Java and nce for GWT, because GWT should not use all Java libraries
* You all say that we need to tell the build that we are using the Google Maps library twice but you only say where to make the change once. You need to include the Setup Eclipse Workspace Step 4 from the Cypal blog
Step 4:
In the Application.java there’s an error in the download file at the end. There’s some ‘s embedded
Question: In section 2 you specify the GWT 1.7.0 and plugin 1.1 versions but the latest (at the time of writing is 1.7.1 and 1.2. Are there problems with the latest versions or was this just that at the time you wrote the blog you had to change to the latest version?
Hello Keith, thank you! These were the latest versions at the time I wrote this tutorial. Now I’m using plugin version 1.2 and for example gwt 1.7.1.
Great tutorial, thanks for sharing!
thank you thank you thank you. GREAT tutorial, easy to follow and was the only way I could set this to work! I really appreciate it
Hi,
While I am running the application (Run As->maven Install) getting the following errors. Could you please help in solving the error. By the way I am just learning gwt/maven/eclipse.
PS: Error message are below.
Regards,
Appu
[INFO] Scanning for projects…
[INFO]
[INFO] ————————————————————————
[INFO] Building Unnamed – com.claudiushauptmann:my-gwt-project-with-maven:war:0.0.1-SNAPSHOT 0.0.1-SNAPSHOT
[INFO] ————————————————————————
[INFO]
[INFO] — gwt-maven-plugin:1.1:generateAsync (default) @ my-gwt-project-with-maven —
[INFO] using GWT jars from project dependencies : 2.0.3
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 0.625s
[INFO] Finished at: Thu Apr 29 10:49:06 CDT 2010
[INFO] Final Memory: 2M/15M
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:1.1:generateAsync (default) on project my-gwt-project-with-maven: artifact not found – Unable to download the artifact from any repository
Hi, there is some of problems eclipse with cypalstudio plugin .
i have placed jar files properly in plugin folder.its showing on window frafernce properly.but not showing in create new project for cypal configuration settings.IDE is eclipse galileo. thanks
Hello!
Thank you for the help. Is it possible to use later versions of GWT (i.e. >= 2.0.1) instead of 1.7.0?
TIA
Rafael
Hi Rafael,
m2eclipse updates the eclipse project settings and provides launch configuration types for maven and thus also the gwt development mode (formerly hosted mode): gwt:run/gwt:debug. m2eclipse does not care about the version of your gwt-user.jar You can find a sample here:
http://code.google.com/p/gwt-multipage/source/browse/tags/gwtmultipage-1.0.0.Beta5/pom.xml
Claudius
Hi narsimhamudiraj,
Id did not proof, whether cypal and m2eclipse work together. I’m happy with the maven goal gwt:run/gwt:debug. Have you been able to fix your configuration yet?
Thanks,
Claudius
Hi, everybody
I follow the tutorial until step 4. Its give me an error
[INFO] Scanning for projects…
[INFO]
[INFO] ————————————————————————
[INFO] Building gwt-maven-archetype-project 0.0.1-SNAPSHOT
[INFO] ————————————————————————
[INFO]
[INFO] — gwt-maven-plugin:1.2:generateAsync (default) @ simpleIntegration —
[INFO] using GWT jars from project dependencies : 2.0.4
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 3.437s
[INFO] Finished at: Tue Aug 03 06:25:32 CEST 2010
[INFO] Final Memory: 3M/15M
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:1.2:generateAsync (default) on project simpleIntegration: artifact not found – Unable to download the artifact from any repository
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.google.gwt -DartifactId=gwt-dev -Dversion=2.0.4 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.google.gwt -DartifactId=gwt-dev -Dversion=2.0.4 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
com.google.gwt:gwt-dev:jar:2.0.4
from the specified remote repositories:
central (http://repo1.maven.org/maven2, releases=true, snapshots=false)
-> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
After I have already done follow it’s instruction and then run it again but the error still occur.
So, now I’m stuck on this. Can somebody help me please?
Thank you very much in advance.
Anything new about Peerawat’s problem? I’m experiencing the same issue:
Build errors for gwt-test; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:1.2:generateAsync (default) on project gwt-test: artifact resolver problem – Transfer error: The server did not respond within the configured timeout.
com.google.gwt:gwt-dev:jar:1.7.1