Getting started with GWT, Maven and Eclipse
In this post, we're going to take a look at how we can work with GWT and Maven when using Eclipse's Integrated Development Environment (IDE).
In this post, we'll:
- Install the gwt-maven-plugin
- Generate a skeleton project using the gwt-maven-plugin archetype
- Enable the Google Plugin for Eclipse
- Test the application in development mode
Prerequisites
You will need a Java SDK (version 1.6 or later), the Eclipse IDE for Java EE Developers (Helios version 3.6.2 or later) and Maven (version 2.2.1).
I started with a fresh install of Eclipse and followed these recommendations when updating "eclipse.ini":
-startup plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.2.R36x_v20101222 -product org.eclipse.epp.package.jee.product -showlocation -showsplash --launcher.defaultAction openFile -vm C:/tools/java/jdk-1.6.0_26/bin -vmargs -Dosgi.requiredJavaVersion=1.6 -Declipse.p2.unsignedPolicy=allow -Xms128m -Xmx512m -Xss4m -XX:PermSize=128m -XX:MaxPermSize=512m -XX:CompileThreshold=5 -XX:MaxGCPauseMillis=10 -XX:MaxHeapFreeRatio=70 -XX:+CMSIncrementalPacing -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:+UseFastAccessorMethods
Note: gwt-maven is deprecated/discontinued. For more information please refer to the gwt-maven wiki.
1. Install the gwt-maven-plugin
Before we can install the gwt-maven-plugin we must first install the Eclipse Web Tools Platform (WTP). In Eclipse choose "Help -> Install New Software..." and paste the update site URL http://download.eclipse.org/webtools/repository/helios/ into the field named "Work with:" then press the Enter key.
Pressing Enter should cause Eclipse to update the list of available plugins:

Select the latest version of the Web Tools Platform (e.g. 3.2.4) click Next and then follow the prompts. When the download has finished and the installation is complete make sure you restart Eclipse.
The gwt-maven-plugin has a dependency on the Zest Visualization Toolkit so we also need to install the GEF SDK. The update site for the GEF SDK is http://download.eclipse.org/tools/gef/updates/releases. As before, paste the update site URL into the field named "Work with:" then press the Enter key.

Select the latest version of the GEF SDK (e.g. 3.6.2) click Next and then follow the prompts. When the download has finished and the installation is complete make sure you restart Eclipse.
Now we can install the gwt-maven-plugin from codehaus.org. As before, choose "Help -> Install New Software..." and paste the update site URL http://m2eclipse.sonatype.org/sites/m2e into the field named "Work with:" then press the Enter key.
Pressing Enter should cause Eclipse to update the list of available plugins:

Select the Maven Integration for Eclipse plugin click Next and then follow the prompts. When the download has finished and the installation is complete make sure you restart Eclipse.
We also need one more plugin, the Maven Integration for Eclipse WTP plugin. The update site for the Maven Integration for Eclipse WTP plugin is http://m2eclipse.sonatype.org/sites/m2e-extras. As before, paste the update site URL into the field named "Work with:" then press the Enter key.

Select the Maven Integration for Eclipse WTP plugin click Next and then follow the prompts. When the download has finished and the installation is complete make sure you restart Eclipse.
And because we started with a fresh install of Eclipse we also need the Google Plugin for Eclipse. The update site for the Google Plugin for Eclipse is http://dl.google.com/eclipse/plugin/3.6. As before, paste the update site URL into the field named "Work with:" then press the Enter key.

Select the Google Plugin for Eclipse 3.6 click Next and then follow the prompts. When the download has finished and the installation is complete make sure you restart Eclipse.
Your list of "Available Software Sites" should now look something like the following:

You might also need to let Eclipse know about your exisitng Maven installations:

2. Generate a skeleton project using the gwt-maven-plugin archetype
Right-click in the Project Explorer and choose "New -> Project...":

Then choose "Maven -> Maven Project" and click the "Next" button:

Choose a Workspace for the new Maven project and then click the "Next" button:

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

Enter the details (known as the Maven coordinates) for the new project and then click the "Finish" button. Unfortunately, there are some issues with the project skeleton that is generated.
I also tried running Maven from the command line:
mvn archetype:generate -DarchetypeRepository=https://nexus.codehaus.org/content/groups/snapshots-group/
-DarchetypeGroupId=org.codehaus.mojo
-DarchetypeArtifactId=gwt-maven-plugin
-DarchetypeVersion=2.1.1-SNAPSHOT
-DgroupId=au.com.uptick
-DartifactId=MyGwtMavenSampleApp
-Dversion=0.0.1-SNAPSHOT
-Dpackage=au.com.uptick.gwt.maven.sample
-Dmodule=MyGwtMavenSampleApp
I got around this problem by using webAppCreator:
webAppCreator -maven -out MyGwtMavenSampleApp au.com.uptick.gwt.maven.sample.MyGwtMavenSampleApp
And, then importing the project into Eclipse (e.g. choose File -> Import..." then "Maven -> Existing Maven Project"):

Note: If you run into any issues when importing a new project try deleting your local Maven repository (e.g. ~\.m2\repository) and repeating the steps.
3. Enable the Google Plugin for Eclipse
If you have an existing Maven project in Eclipse and want to enable Google Plugin for Eclipse (GPE) functionality then follow these steps.
In Eclipse, open your project's properties (e.g. right-click in the Project Explorer and choose "Properties"). Under Google | Web Application, check the "This project has a WAR directory" box and point it to your project's src/main/webapp directory. This is the standard WAR source folder for Maven Web projects. Be sure that the "Launch and deploy from this directory" box is NOT checked.

Under Google | Web Toolkit, select the version of the GWT SDK you're using.

Under Java Build Path, select the Order and Export tab and move all Maven dependencies to the BOTTOM. Otherwise, GPE will see the GWT SDKs from the Maven repository on the build path and complain that they are not valid. This is because GPE expects a specific SDK structure used to enable other tooling.

Also under Java Build Path, select the Source tab and ensure that the Build output directory is enabled and pointing to target/your-project-name/WEB-INF/classes.

Finally, and this is very important, the first time you launch your project using "Run As -> Web Application" (or Debug), you will be prompted to select the war directly. This is NOT src/main/webapp, but rather the WAR output folder. If you make a mistake, simply go to "Run -> Run Configurations..." and remove any old configurations for the project. GPE will then prompt you again the next time you try to "Run As -> Web Application".

4. Test the application in development mode
At this point, you should be able to compile and run the new project in GWT Development Mode. Right-click on the pom.xml in the Project Explorer and choose "Run As -> Maven Build..." and run the "gwt:run" goal:

The Maven Console shows the Maven output that normally appears on the console when running Maven from the command line. You can open the Console View by choosing "Window -> Show View -> Console" then click on the little arrow on the right hand side of the Open Console icon and select Maven Console.


Comments
You are awesome
It's my first reply on a blog ever.
I'm a computer engineering student and we have a project based on GWT. We spent 3 days trying to figure out how to use maven, gwt, gwtp integrate all of this in eclipse. Good documentation and tutorials are hard to come by and we really did have a hard time understanding all of this. Even thought we are now past the stuff covered by your tutorials, I would like to thank you for putting up this work as I'm sure it will greatly help other people.
Keep up the good work!
Thank you
I have to agree with the previous entry, this is an awesome piece of work.
Thanks a lot.
Re: You are awesome
Hi,
Thanks for the feedback it is much appreciated :-)
Cheers
Rob
WAR file
Thanks for the tutorial it was really informative, maybe one day you could also go over generating a deployable war file.
Thanks again.
Re: WAR file
Hi,
You might like to take a look at Maven: The Definitive Guide.
Cheers
Rob
Maven 2.x vs 3.x
Why did you use the old maven and not the new one?
With this configuration it is possible to use the GWT-Eclipse plugin provided by google?
Re: Maven 2.x vs 3.x
Hi,
I used the version of Maven (2.2.1) that I am familiar with.
I use the "gwt-maven-plugin" and the "maven-eclipse-plugin":
->
<properties>
<gwt-maven-plugin.version>2.2.0</gwt-maven-plugin.version>
<maven-eclipse-plugin.version>2.8</maven-eclipse-plugin.version>
<properties>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt-maven-plugin.version}</version>
<configuration>
...
</configuration>
</plugin>
<!-- Maven Eclipse Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${maven-eclipse-plugin.version}</version>
<configuration>
...
</configuration>
</plugin>
->
Cheers
Rob
Thank you
Thanks from Poland :)
Module needs to be recompiled?
Hi, things work fine.
However, when I call "mvn clean package" from the command line, the resulting webapplication displays "module needs to be recompiled" in the browser.
When I compile the app using the "red gwt compile"button from Eclipse, and use "mvn package" from commandline afterwards, the resulting webapp works fine. What should be done such that "mvn clean package" will build the webapp correctly?
Thanks
Rick
Re: Module needs to be recompiled?
Hi,
I received the same error a few times as well.
From the command line try:
mvn gwt:clean
mvn clean package
mvn gwt:run
Cheers
Rob
Re: Module needs to be recompiled?
Hi Rob,
So it seems that the gwt:clean goal is not executed when mvn clean is executed, hmmm...
Good to know, thanks!
Rick
How to add an archetype?
Hi,
Thanks for posting these tutorials, they're great. I'm pretty new to Maven. I've followed your guide but can't get the gwt-maven-plugin version 2.2.0 listed in the new maven project wizard. It shows version 1.2 only. Do I need to add a repository or archetype catalog somewhere? I've browsed http://repo1.maven.org/maven2/org/codehaus/mojo/gwt-maven-plugin/ and can see up to version 2.3.0. Does maven comes with repo1.maven.org remote repository configured and if not, how do I do that?
Thanks again.
Re: How to add an archetype?
Hi,
In the "New Maven Project" wizard on the "Select an Archetype" page, click the "Add Archetype" button and enter:
Archetype Group Id: org.codehaus.mojo
Archetype Artifact Id: gwt-maven-plugin
Archetype Version: 2.2.0
Repository URL: https://nexus.codehaus.org/content/groups/snapshots-group/
Cheers
Rob
Re: How to add an archetype?
Hi,
Although that allowed me to select the gwt-maven-plugin 2.2.0 archetype, the project skeleton that is generated doesn't work (e.g. throws a lot of errors like 'GreetingServiceAsyc cannot be resolved to a type').
The only way I can create a Maven GWT Project is by using webAppCreator, importing the generated code as an existing maven project and then configuring it as you explained (build path order and export, gwt settings, etc).
Thanks!
Thanks a lot
Saved me a lot of time :)
Eclipse Indigo
Hi,
If you are using Eclipse Indigio then take a look at this link:
-> http://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven
Cheers
Rob
Many Thanks
Hi Rob,
I've been spending hours & hours reading your tutorials. You're a genius! Thank you so much for sharing. I'm basically trying to 'copy' your posts in order to get a personal Web application working. I managed to make your latest release of gwt-cx work but then I didn't really know how to adapt it when working with Maven. So I tried to use the first release again (without maven) and I was faced with compatibility issues (GWT & GWTP).
Ok, Ok, now you're thinking I'm not gifted .. well maybe but I will keep trying :-) I'm taking a big deep breath and I feel ready to jump back to your latest example again.
If one day, I become an expert (you never know :-) and I build professional webapps, I'll donate some money from my webapps revenue as R&D costs :-)
Thanks a lot Rob.
Running the application from the Eclipse IDE
Hi,
If I run the application from maven in debug mode as shown above, it works fine. However, if I run the application directly in Eclipse as a web application using a web server like Tomcat, it displays the page, but the page does not have a field to enter the name nor a button to send. Can you tell me why this is happening? I was thinking it should work properly either way. Perhaps some libraries are not loaded properly. Any suggestions would be appreciated.
Thanks
Tom
Re: The Eclipse IDE
Hi Tom,
Yes, there are some addtional libraries (e.g hsqldb, tomcat-jdbc, mail, etc.) required by the application that must be placed in Tomcat's lib directory.
You can find them here:
-> http://code.google.com/p/gwt-cx/source/browse/#svn%2Ftrunk%2Fgwtcx%2Ftom...
BTW, you can ask questions and make comments or suggestions in the gwt-cx discussion group.
Cheers
Rob
Some additional configuration
Hi Rob,
Thanks for your useful tutorial, it saves me a lot of work :-)
At the end I had to do also the following configuration (missing in your tutorial):
From Eclipse -> Right Click on the project -> Properties -> Java compiler change all from 1.4 to 1.6 (1.4 does not support annotations and others stuff). I am using: jdk1.6.0_30, JRE 1.6, gwt-2.4.0, eclipse-jee-helios-win32.zip
Bye, Domenico