Knowledge Seeking

GWT – Adding Jar Dependency to our GWT project. (Maven-Gwt-Plugin) March 17, 2011

Filed under: GWT,Java — nicozan @ 4:16 pm


You might be asking yourself, Why am I doing this post?, because you might think that adding a dependency in a GWT Project using the Maven-GWT-Plugin is just as simple as adding a dependency in a Regular Maven project. Sorry to disappoint but apart from that you have to do something else … 🙂


Every gwt project has a gwt.xml file that represents the GWT-module. This file contains specific information related to the module, for example:
—Entry-point (The java class that represents the web page that is going to be displayed in the web browser)
—Inherits (External Modules that our GWT-Module uses)

These two elements shown above are represented by tags. These tags are child elements of the root element module . The next code snippet shows how the gwt.xml file is structured.

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='MyWebApp'>
 <!-- Inherit the core Web Toolkit stuff.                        -->
 <inherits name=''/>
 <!-- Inherit the default GWT style sheet.  You can change       -->
 <!-- the theme of your GWT application by uncommenting          -->
 <!-- any one of the following lines.                            -->
 <inherits name=''/>
 <!-- <inherits name=''/> -->
 <!-- <inherits name=''/>     -->

 <!-- Other module inherits                                      -->
 <inherits name='com.wordpress.nicozan.Model'/>

 <!-- Specify the app entry point class.                         -->
 <entry-point class='com.wordpress.nicozan.client.MyWebApp'/>

 <!-- Specify the paths for translatable code                    -->
 <source path='client'/>
 <source path='shared'/>

As you can see the name of the gwt.xml file is the same, and must be, as the Entry-point Java Class name. There are some modules that are standards and need to be inherited, (i.e :

Adding Jar Dependencies

Let’s consider the MyWebApp.gwt.xml shown before and that we have a project with two sub modules : webapp and model. The project has the next directory structure:

|- pom.xml
|- model/                                      (External JAR module:)
|  |- pom.xml
|  \- src/main/java/
|     \- com/wordpress/nicozan/
|        |- Model.gwt.xml
|        \- model/utils/
\- webapp/                                      (GWT-Module)
 |- pom.xml
 \- src/
    |- main/java/
    |  \ -com/wordpress/nicozan/
    |     |- MyWebApp.gwt.xml
    |     \- client/
    \- main/webapp/
       \- WEB-INF/web.xml

Take special attention to the model module. There is a gwt.xml file (Model.gwt.xml) that it’s in charge of specifying the source path from where the resources we’ll be built so the webapp module will then be able to use them. The Model.gwt.xml will look like this:

<inherits name=""/>
<source path="model"/>

The Java classes are found recursively so you just need to specify the root directory.
The next thing to do is to generate this resources so the GWT webapp can use them. The pom.xml of the model module would look like this:

<project xmlns=""




Now, when you do mvn clean install of the parent-project, the resources will be generated and the GWT webapp can consume them. 🙂

– Don’t forget to add all the dependencies as you usually do in your common maven projects.
– Remember to add the maven-gwt-plugin to the pom.xml of the resource you want generate.
– You don’t need to do all the steps explained above if you are adding dependencies that are going to use on the server-side. In that case just add the dependency to the pom as usual.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s