Having used Google Web Toolkit to build an application, I found out that I had to write a good portion of code, which might as well be generated automatically. I then decided to mess around with XDoclet a little to see if it was possible to make a new module. It was, and now you can use it too.
Download
xdoclet-gwt-module-0.5.jar
xdoclet-gwt-module-0.4.jar
xdoclet-gwt-module-0.3.jar
xdoclet-gwt-module-0.2.jar
xdoclet-gwt-module-0.1.jar
Changelog
0.5: Added support for @gwt.typeArgs in service methods.
0.4: Added support for setting ServiceFactory prefix (set prefix attribute in servicefactory tag in build.xml), @gwt.style and @gwt.script in EntryPoint classes. See this post for more information.
0.3: Added support for file upload, added @gwt.inherits tag instead of inherits parameter in @gwt.module. This means that it's possible to inherit from multiple modules.
Documentation
Basically, it can generate service interfaces, async services interface, module definitions (.xml.gwt), and a basic web.xml file. Finally, it can create a service factory for creating new Async-objects.
Service interfaces
When creating a remote service, just annotate the class like this:
-
package dk.contix.gwt.service;
-
-
/**
-
* @gwt.interface service="dk.contix.gwt.shared.RemoteService" path="/remoteService"
-
*/
-
public class RemoteServiceImpl implements RemoteService {
-
-
/**
-
* @gwt.serviceMethod
-
*/
-
public String getStuff(String what) {
-
// code here
-
}
-
}
This will create the interface dk.contix.gwt.shared.RemoteService containing all methods which are annotated with @gwt.serviceMethod. It will also generate the async interface in dk.contix.gwt.shared.RemoteServiceAsync
Modules
To generate module definitions (.gwt.xml files), annotate the EntryPoint classes, like this:
-
package dk.contix.gwt.client;
-
-
/**
-
* @gwt.module package="dk.contix.gwt" include="client,shared"
-
*/
-
public class Client implements EntryPint {
-
// code here
-
}
This will generate a file in dk/contix/gwt calles Client.gwt.xml. The file will contain the entry-point declaration, all remote servlets, and additional source paths (those specified in the include parameter).
ServiceFactory
If a service factory is generated, a class with static methods for creating instances of the Async interfaces will be created. The factory class will automatically detect url prefixes (if the application is deployed in another context than ROOT).
Generating the files
Create a build.xml file for Ant, if you don't already have one. Include the following target:
-
<path id="classpath">
-
<pathelement location="src"/>
-
<pathelement location="${build.dir}/classes"/>
-
<fileset dir="lib">
-
<include name="**/*.jar"/>
-
</fileset>
-
</path>
-
-
<target name="generate">
-
<taskdef resource="xdoclet/modules/gwt/doclet.xml" classpathref="classpath"/>
-
-
<gwtdoclet destdir="src">
-
<fileset dir="src">
-
<include name="**/*.java"/>
-
</fileset>
-
-
<interface/>
-
<async/>
-
<module/>
-
<webxml output="web.xml"/>
-
<servicefactory class="dk.contix.gwt.client.ServiceFactory"/>
-
</gwtdoclet>
-
</target>
Finally, place xdoclet-gwt-module-0.2.jar in lib/ so that it becomes a part of the classpath. xdoclet-*.jar and xjavadoc-*.jar is also required. They can be downloaded from xdoclet.sourceforge.net.
Bootstrapping
When a new remote service is created, there's no interface to implement. I work around this simply by annotating the service implementation, generating the code, and then adding the implements declaration.
Inheritance
If a module inherits another, this can be specified too, like this:
-
/**
-
* @gwt.inherits name="dk.contix.gwt.BaseModule"
-
* @gwt.inherits name="com.google.gwt.user.User"
-
*/
-
public class Module implements EntryPoint {
-
...
-
}
File Uploads
The XDoclet module supports code generation for file upload support. The generated code includes a factory class for FormPanels, GWT module xml configuration and web.xml configuration. To use, add one or more @gwt.upload annotations to client classes which need upload capabilities:
-
package dk.contix.gwt.client;
-
-
/**
-
* @gwt.upload path="/upload" servlet="dk.contix.gwt.service.FileUpload"
-
* @gwt.upload path="/jpegUpload" servlet="dk.contix.gwt.service.FileUpload"
-
*/
-
public class UploadPanel extends Composite {
-
public UploadPanel() {
-
VerticalPanel p = new VerticalPanel();
-
final FormPanel fp1 = UploadFactory.createUpload();
-
fp1.setWidget(p);
-
fp1.addFormHandler(...);
-
-
final FormPanel fp2 = UploadFactory.createJpegUpload();
-
fp2.setWidget(p);
-
...
-
}
-
}
To generate the factory, a line needs to be added to the ant build target in the gwtdoclet tag:
-
<gwtdoclet destdir="target/gensrc">
-
<fileset dir="src" include="**/*.java"/>
-
<interface />
-
<async />
-
<module />
-
<servicefactory class="${serviceFactory}"/>
-
<uploadfactory class="${uploadFactory}"/>
-
<webxml output="web.xml"/>
-
</gwtdoclet>
The upload servlet isn't generated, so you need to implement it yourself. Search for implementations in the GWT group.
typeArgs
Add @gwt.typeArgs to service methods to tell the GWT compiler which types are contained in a collection:
-
/**
-
* @gwt.serviceMethod
-
* @gwt.typeArgs dk.contix.Test
-
*/
-
public List getObjects() {
-
return new ArrayList();
-
}
Don't include <> in the annotation as you would do when using GWT directly.




[...] GWT XDoclet [...]