Inside a GWT application we have a "shared" package which contains, as its name implies, objects shared between client-side and server-side code. We have a multi-module maven project:
+ server
| |
| + businessLogicPackage
|
+ gwt
|
+ client
|
+ server
| |
| + converter
| |
| + rpc
|
+ shared
Each time I need to reuse a shared object in the server module, I need to convert the shared object using some converter located in gwt/server/converter. I tried to use inheritance and have the shared objects inherit classes from the server/businessLogicPackage, thinking I could get away with a simple casting operation. This produces an error. Obviously GWT can't compile the sources from an external module.
> No source code is available for type server.businessLogicPackage.x; did you forget to inherit a required module ?
Knowing that:
Could anyone share some best practice / alternative with me ? What's trendy now in 2014 ?
Your problem is to use classes from gwt module and shared package in server module without manual conversion ?
You could simply create a third module named shared for example that contains the classes used by gwt client side and server module.
gwt and server modules depend on this new shared module.
For GWT to have access to the source, you add a MySharedModuleName.gwt.xml
to the new module and add its package as source. In your GWT module, add an inherit tag for MySharedModuleName
.
And then, GWT needs access to the sources. You can add in your gwt module pom a dependency to the sources jar if you create it : <classifier>sources</classifier>
. Or add the goal gwt:resources in your shared module to include the sources inside the jar.