Compared to GWT Documentation on directory layout, the plugin follows Maven conventions:
Compared to the directory layout used by GWT, notice that the /war folder is replaced by the src/main/webapp folder, following maven-war-plugin conventions. The project structure generated by the gwt-maven-plugin archetype allready includes the adequate Google Plugin for Eclipse configuration. If you manually migrate a GWT project to Maven, you will need to configure the Google Plugin for Eclipse to use this folder.
In order to use gwt-maven-plugin, you will need to configure it using the plugins section of your POM.
You also need to include the GWT dependencies in your POM, and use the adequate gwt-maven-plugin version. The plugin will check this version and warn if you try to use inconsistent releases.
<dependencies> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-servlet</artifactId> <version>2.7.0</version> <scope>runtime</scope> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-user</artifactId> <version>2.7.0</version> <scope>provided</scope> </dependency> <dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>2.7.0</version> <executions> <execution> <goals> <goal>compile</goal> <goal>generateAsync</goal> <goal>test</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Note : Don't define gwt-dev as project dependency : this JAR only contains gwt SDK tools and has many common libraries packaged that may conflict with the ones defined for your project, resulting in uncomprehensible NoSuchMethodErrors. The gwt-maven-plugin will automagically resolve the required dependency and add it to classpath when lauching GWT tools.
Large Maven projects often are divided into sub-projects. This section describe the maven configuration needed to use such layout on GWT projects with gwt-maven-plugin. If you're not familiar with multi-module layout, please read first the related maven documentation.
NOTE that GWT also has a notion of module. Both Maven and GWT use the term module to define units of modularization. To a degree both concepts go hand in hand, as gwt-modules define boundaries at which Maven-modules might be cut. To not confuse these two terms though, for the rest of this section we will use the term module, if we talk about GWT-modules, in contrast to the term project, if we talk about Maven-modules.
First, we will setup a basic Maven project structure consisting of two sub-projects: one containing domain code and another one containing the actual GWT application. Like other web application, a common pattern is to separate GUI functionality from domain functionality (among others) :
parent/ (aggregating parent project) |- pom.xml | |- domain/ (domain code, etc.; packaging: JAR) | |- pom.xml | \- src/main/java/ | \- org/codehaus/mojo/domain | \- User.java | \- webapp/ (GUI code; packaging: WAR) |- pom.xml \- src/ |- main/java/ | \ -org/codehaus/mojo/ui/ | |- Hello.gwt.xml | \- client/Hello.java \- main/webapp/ \- WEB-INF/web.xml
To convert the domain project to a valid GWT module, we add a module descriptor Domain.gwt.xml to the domain project that we can extend from our webapp Hello module.
|- domain/ | |- pom.xml | \- src/main/java/ | \- org/codehaus/mojo/domain/ | \- User.java | \- src/main/resources/ | \- org/codehaus/mojo/ | \- Domain.gwt.xml (Additionnal gwt.xml module file)
<module> <inherits name="com.google.gwt.user.User"/> <source path="domain"/> </module>
The domain project it not yet a valid GWT module : GWT compiler requires Java source files.
First option is to use the gwt:resources or gwt:source-jar goals to attach java sources and resources in the generated jar. The side effect is that this jar will include java sources, that may not be what you want to do if you use it elsewhere, typically in the webapp servlets.
Second option is to configure Maven to package a source-jar for domain project. In the webapp project, configure gwt-maven-plugin to use it as additional source for the domain dependency :
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>2.7.0</version> <executions> ... </executions> <configuration> <compileSourcesArtifacts> <artifact>org.codehaus.mojo:domain</artifact> </compileSourcesArtifacts> </configuration> </plugin>