David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler

    Web app developer since 1994 and Google Cloud Platform Instructor now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 223 other followers

  • Sleepless Nights…

    November 2009
    S M T W T F S
  • Blog Stats

    • 1,033,665 hits

Tips on organizing GWT modules

Posted by David Chandler on November 19, 2009

My current project is at the point where I’m starting to work on an administrative UI. I wanted to package it as a separate GWT module in order to not clutter up the main application module. There is some code such as the domain model that is shared between the main app and the admin code, so the question is how to organize the modules in order to share code between them.

My first attempt was to have the admin module simply inherit the main app module named ROA in admin.gwt.xml, like this:

	<inherits name="com.roa.app.ROA" />

This had two undesired results:

  • Both modules declare an entry-point, so GWT tries to load both, beginning with the inherited module.
  • At GWT compile time, all the code from the inherited module was duplicated under the admin module in the war structure.

My next attempt was to have the admin and app Java packages each point to a third sister package called “common” containing the domain model and other common code. Java is happy with this, but in order for GWT to compile the common code into JavaScript, you must make it a module. So now there are three packages, each with its own module:


Admin and app each have entry points and inherit the common module, which does not define an entry point. This works fine.

In the common module, I use the source tag to include multiple directories instead of just the default client directory. Note that if you specify one or more source directories, GWT no longer compiles the client directory by default, so you have to explicitly include it, as well:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.1/distro-source/core/src/gwt-module.dtd">
	<inherits name="com.google.gwt.user.User" />

	<source path="client" />
	<source path="domain" />
	<source path="presenter" />

Also, I moved the “public” directory containing CSS and images from the admin and app packages into the common module, and discovered that GWT does not create a “common” directory in the war, but rather copies the contents of the public folder from the inherited common module into both the admin and app module directories. That’s OK, though, as my CSS and images now exist in only one place in source control.

A final note: thank goodness for Eclipse refactoring tools. The easiest way to move a package (say, com.roa.app.domain to com.roa.common.domain) is to select it in the Project Explorer, then right-click, Refactor, and Rename… It’s a bit non-intuitive to use Rename rather than the Move command, but the latter appears to work only for moving packages to another project or source folder, whereas rename allows you to “move” it within the current source folder. Eclipse automatically fixes all the package and import declarations in affected code (whew!).

14 Responses to “Tips on organizing GWT modules”

  1. perwiklander said

    Good one on the package renaming (moving). I’m an Eclipse user since five years but I guess you learn something new every day.

    My problem with the common code is that it is shared by an other totally non GWT project. I created a special package for the classes I needed to make GWT compatible and added a common.gwt.xml. I works in hosted mode since eclipse finds the source files but when compiling the GWT code with maven, the GWT compiler can’t find the sources from the other project. Hosted mode works for a few more days, then I’ll have to start digging.

    • You should be able to package the common module as a jar and put the jar in the WEB-INF/lib directory of your other project just like any other third party lib. Make sure you have a <source> tag in your common.gwt.xml for each top-level dir/package that contains GWT code.

  2. perwiklander said

    It turned out to be easy. If you need the sources of a maven project during compile time you just add an extra dependency marked with


    So in web-app/pom.xml I now have the following and gwt-maven finds the needed sources.


    So now I can build everything headless. It seems to work fine, compiling six versions of everything and all, then I get this in the browser:

    GWT module 'app' needs to be (re)compiled, please run a compile or use the Compile/Browse button in hosted mode

    Oh, well. That’s a problem for another day. It’s Friday night here in Stockholm.

  3. perwiklander said

    Hmm, all XML was eaten, of course… although I used both code and pre. The tag around the “sources” part is a “classifier”, the rest is the standard project coordinates.

  4. […] multiple EntryPoints, or everything all in one. Although there is plenty of discussion out there (here, here, here, and here), the general consensus is still a little muddy. Like anything in our […]

  5. FishKillah said

    Please, I am a beginner in GWT…I just would like to structure my app with an “admin” and a “normal-mode”. Is there any example for this ? (to see more details about how is structured the code). Thanks you.

  6. Hello,
    I want help regarding gwt web project including 3rd party environment. I am new to GWT. GWT Application had been created in Intellij but want to migrate in eclipse Indigo. It contains lot of hard code. and two gwt modules. We have domain library which contains java source code has been used in thousands of related files. I don’t want to change there address that may be painful. Like import domain.xxx.xxx.xx.xx. I put this domain in shared folder in gwt application in eclipse. And declaired it as source folder. So address didn’t change. But problem is that this library is used by both client and server side and compiler doesn’t create its .js file compiling. I have used the method you mention above but no work? Actualy I don’t want to put this folder in project root directory bcz then I have to change reference address. PLEASE Help!!!!!
    Thanks in advanced.

  7. Noopur said

    Hello David,

    I want to have a common page header widget in my project in common module, problem is that I want to have activities for service calls to backend.

    is it okay to write common module with a entry-point class and do not add the widget to root panel ?

  8. anu said

    Thanks for this article. We have similar project structure with common having no entry point. common.jar is inherited in module A and module B (both of these have entry points ). I am trying set a value in common class from module A and access it from module B. The value I get in module B is always null, the reason might be that A and B have their local copy of common. Is there a way both A and B share the same copy of common? or to achieve this we should think of restructuring the project like having one parent entry point module etc. ?

  9. Thank You

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: