A life committed to learning.

GWT Quickstart Project with Maven+GWT2.3+GIN1.5


Been a while… This post will show you, and remind me in the future, how to quickly setup a

GWT 2.3 project with Maven2 and GIN 1.5. I’m using Ubuntu, but the essential steps should be the same in any operating system.

Let’s start.

Assuming you have maven installed, just run:

mvn archetype:generate -DarchetypeRepository=repo1.maven.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0-1

Then, enter the details for you new GWT 2.3 project. Don’t forget that the property for ‘module’ should be a valid Java Class name, so use camel case when setting the name of module.
My configurations are something like:

Define value for property 'groupId': : eu.jpereira.gwt
Define value for property 'artifactId': : quickstart
Define value for property 'version': 1.0-SNAPSHOT:
Define value for property 'package': eu.jpereira.gwt:
Define value for property 'module': : Quickstart
Confirm properties configuration:
groupId: eu.jpereira.gwt
artifactId: quickstart
version: 1.0-SNAPSHOT
package: eu.jpereira.gwt
module: Quickstart

Now, we just need to add the dependency to GIN 1.5. Open the generated POM for the Quickstart project and add the dependency for GIN 1.5:

<!-- GIN Stuff -->

Now you have a GWT 2.3 project with GIN 1.5 and Maven.
To finalize, let just remind how to setup GIN with the GWT project.
Generate the eclipse project:

mvn eclipse:eclipse gwt:eclipse

Open the project in eclipse and edit the *.gwt.xml (in my case, this is the file Quickstart.gwt.xml) file, located under “src/main/resources/” to import the GIN module:

<inherits name="com.google.gwt.inject.Inject" />

Create the GinModule, the class file that will configure the dependency injection for your application. You can have any number of GinModules. Check the documentation here: http://code.google.com/p/google-gin/wiki/GinTutorial
I like to keep everything related to GIn under the package *.client.gin. My Module is this:

package eu.jpereira.gwt.client.gin;

import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Singleton;
import eu.jpereira.gwt.client.QuaickstartApplication;

public class QuickstartGinModule extends AbstractGinModule {

	protected void configure() {

Here I’m only binding the QuickstartApplication object, which is my main application, like this:

package eu.jpereira.gwt.client;

import com.google.gwt.user.client.Window;

public class QuaickstartApplication {
	public void run() {
		Window.alert("Hello World!!!");

Back to Gin setup, let’s create the Ginjector. Create a new Interface that extends from Ginjector:

package eu.jpereira.gwt.client.gin;

import com.google.gwt.inject.client.GinModules;
import com.google.gwt.inject.client.Ginjector;
import eu.jpereira.gwt.client.QuickstartApplication;
public interface QuickstartInjector extends Ginjector{
	QuickstartApplication getQuickstartApplication();

Finally, it’s time to use it. In the Quickstart.java, which contains the entry point to the application, remove everything, create the injector and start your application.

package eu.jpereira.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;

import eu.jpereira.gwt.client.gin.QuickstartInjector;

 * Entry point classes define <code>onModuleLoad()</code>.
public class Quickstart implements EntryPoint {

	 * This is the entry point method.
	public void onModuleLoad() {
		QuickstartInjector injector = GWT.create(QuickstartInjector.class);



Now, run the application with:

mvn gwt:run

And you should see the “Hello World!!” alert.

BTW, you can download the project here.

Happy coding!!!!



View more posts from this author

Leave a Reply

Your email address will not be published. Required fields are marked *