Fork me on GitHub
NOTICE There is a new plugin (archetypes and eclipse integration), a fresh start that correctly support multi-module projects, it is not version-bounded with GWT, support multiples GWT versions and other fixes, improvements and best practices. This plugin is now considered the legacy GWT maven plugin (aka mojo GWT maven plugin) and the new one is considered the new generation GWT maven plugin (aka tbroyer GWT maven plugin). The legacy maven plugin is still supported but it is strongly encouraged to use the new one for new projects.

Writing a GWT library (a.k.a. gwt lib)

A GWT library can be used to package classes for mutualization and/or modularization. A GWT library is just a java archive (JAR) containing both classes and java sources for later GWT compilation and a gwt.xml module descriptor.

Packaging

The only distinction with a standard JAR project is the mix of sources and classes in the output folder. A simple way to achieve this is to add a dedicated resource in the POM :

    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.java</include>
          <include>**/*.gwt.xml</include>
        </includes>
      </resource>
    </resources>

Using general purpose JARs as GWT library (a.k.a. shared lib)

Many users want to use common usage libraries as GWT modules. Some would like to reuse the server-side business classes on client side, using a shared Maven module. The requirement to include sources in the JAR can then be annoying : including sur JAR in the webapp means the source code will be distributed with the application.

As the sources are not included in the JAR, you need to use the maven convention for source jars to create a ''sources'' package, and include it as a ''clasifiersources/clasifier'' dependency.

<dependencies>
  <dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>domain</artifactId>
    <version>${project.version}</version>
    <classifier>sources</classifier>
    <scope>provided</scope>
  </dependency>
</dependencies>

The only missing fragment to allow using this library from your GWT code is to create a ''gwt.xml'' module file. Create file ''com/mycompany/Domain.gwt.xml'' to match package ''com.mycompany.domain'':

<module>
  <inherits name="com.google.gwt.user.User"/>
  <source path="domain"/>
</module>

If you have control of the ''domain'' lib, include this file in the ''domain'' project:

  |_ domain
  |  |_ src/main/java/com/mycompany/domain/SomeDomainClass.java
  |  |_ src/main/resources/com/mycompany/Domain.gwt.xml
  |_ webapp
     |_ src/main/resources/com/mycompany/web/MyApp.gwt.xml

…otherwise, add the GWT module in the ''webapp'' project:

  |_ domain
  |  |_ src/main/java/com/mycompany/domain/SomeDomainClass.java
  |_ webapp
  |  |_ src/main/resources
        |_ com/mycompany/Domain.gwt.xml
        |_ com/mycompany/MyApp.gwt.xml