In GWT recommended project structure, client code and server code are
placed in one project. I find this structure is not so development-
friendly in practice. (GWT 1.6 has some new update to the project
structure to make it more like standard WAR project, but client and
server code are still in one project.)

Client code will be eventually compiled to Javascript and run on web
browser. Server code will run on web server. These two parts of code
shouldn’t reference to each other. The only connection between them
should be the RPC interface (sub-interfaces of RemoteService) and DTOs
(the Java objects get transmitted between client and server). Any
attempt to let your widget reference to an RPC implementation Servlet
or let the Servlet reference to a widget is wrong. However, your Java
compiler (not GWT compiler) can not detect this kind of error, as
these Java classes are all in the same project, and they are “allowed”
to reference to each other. You can’t detect the error either in
hosted mode, because client and server code run in same JVM in hosted
mode. You only can find out half the issue when you call GWTCompiler
(Compiler in GWT 1.6) to translate the client to Javascript. I say
half because GWTCompiler only shows you the toxic references from
client to server, but not the other way.

A solution would be to have three projects instead of one:
MyProjectRpc
MyProjectGwt
MyProjectWeb

MyProjectRpc is a GWT module. It only contains RemoteService
interfaces and DTOs. It has no UI or widgets.
MyProjectGwt is your client module. It inherits MyProjectRpc, and
contains widgets. MyProjectGwt’s Java build path includes
MyProjectRpc.
MyProjectWeb is your server project. It is a standard WAR project.
Your RPC implementation servlets go here. Its Java build path includes
MyProjectRpc.

Therefore, both MyProjectGwt and MyProjectWeb reference to
MyProjectRpc only. If your widgets incidentally reference to a
servlet, Eclipse (Java compiler) will tell you right away.

To make above solution work, you need to configure GWTCompiler to
output to MyProjectWeb instead of the default folder www. (-out
argument will do the job.) You also need to run your own web server
for hosted mode instead of GWT’s internal Tomcat. (Pass –noserver to
GWTShell.)

There may be better way to do it. Please share your idea for a better
project structure. I would appreciate if developers from Google could
provide advice.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to