GWT - Project (Module) Layout
November 1st, 2008I started a GWT project recently and struggled for a while on how best to separate the project into smaller modules. What I wanted was to be able to throw the UI over a fence and have someone else design and build it, and myself focus only on the server-side coding part. After several iterations and trial and error what we came up with was this:
- MyProject-Server
- MyProject-Shared
- MyProject-UI
The MyProject-UI (client) module is a typical GWT application. However, when you create a servlet to handle RPC calls you stub out the response, and don’t write any code that relies on server resources like session contents or database calls.
MyProject-Shared contains the interfaces to the servlets, and any objects required by their method signature. When creating this project keep in mind that the package has to be a child of your main GWT module. When this project is linked to the client project it will compile to JavaScript, and when it is linked to the server project it will compile to Java.
MyProject-Server contains all business logic for your application, and the same servlets that exist in the client module, but this time with an implementation that utilizes any necessary server-side resources. Through the magic of ant you combine all three projects, such that the server module servlet classes step on the fake / mock / stub classes in MyProject-UI.
If anyone reading this has any other / better ideas please let me know. Especially if someone has tried this and came across issues? The big plus for me is that this approach forces you to keep business logic / server-side code out of your user interface. Because everything in the GWT client project compiles down to JavaScript GWT will yell at you if you even try to put something in there that doesn’t belong.