I've recently come across a situation where I had to construct a GWT package in a jar file, something similar to gwt-user.jar. This describes why I wanted to do this and how to do it with maven.
In GWT application you will have some classes that are passed between the client and the server. These classes need to be marked with the IsSerializable interface and their source code needs to be available to the GWT java to javascript compiler. For a simple application these are most easily defined in the client portion of a single GWT package, which is build by a corresponding maven module. With larger projects, for ease of development and maintenance, it's better to treat the GWT package as a client and it's facade and to move the server code to its own maven module. The GWT package still has a server portion but it's a thin layer that calls through to classes from the main server module. Now though you have the problem of where to put the classes for client server communication.
I'd like to be able to construct the server independent of the client so that it doesn't depend on any GWT code. This gives me two choices. The first is to have the server portion of the GWT package convert from the data transfer objects provided by the server module into the data transfer objects defined by the client portion of the GWT package. I'd prefer to avoid this extra work so what I wanted to do is define a set of interfaces for a factory to construct the DTOs and the DTOs themselves. Then the server code could be programmed in terms of the interfaces, the DTOs in the client portion of the GWT package could implement those interfaces, the server portion of the GWT package could provide the implementations to the server module and all would be well.
To create a GWT package containing the interfaces I created a maven module with very simple module file.
<module> <inherits name="com.google.gwt.user.User"/> </module>
For the jar file created from the maven module to work as a GWT package it must contain the GWT module file and the java source code as well as the compiled classes so that the GWT java to javascript compiler can access them. To do this I configured an additional plugin in the pom. I used the antrun plugin to copy the module file and java source into the target/classes directory.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<tasks>
<copy todir="${basedir}/target/classes">
<fileset dir="${basedir}/src/main/java">
<include name="**/*.java"/>
<include name="**/*.xml"/>
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Posted by Alex at December 24, 2006 10:05 PM