¿Por qué las clases de interfaz de servicio GWTRPC * van en el paquete ".client" en lugar de ".shared"?

Looking at the GWT sample apps and the RPC tutorial the following package conventions are used:


Though the GWT docs are very sparse on best-practices what components get included where at runtime, the clear intuition is:

  • client - Compiled into JavaScript by GWT compiler
  • server - Compiled into bytecode by javac
  • shared - Compiled into JavaScript by GWT compiler y compiled into bytecode by javac

This would lead one to believe that code in client debemos no be on the compile-time sourcepath of javac. Yet since GreetingServiceImpl implementos GreetingService, clearly code in client needs to be on the sourcepath during compilation, and included on the runtime classpath at deployment.

Given this, why doesn't the GreetingService interface go in shared?

If you try to put it in shared,la GWT Eclipse Plugin complains "Missing Asynchronous Interface"...

preguntado el 27 de agosto de 11 a las 19:08

3 Respuestas

Let's try to be clear :

  • No hay técnico diferencia entre el cliente y el compartido package, it's only a matter of convention. Both are declared as source packages in your module (the .gwt.xml archivo)
  • cliente y compartido package get both compiled into javascript y bytecode
  • On servidor side, the bytecode for the whole client part is usually available, although most of it is no utilizado.
  • Therefore, some people just remove the compartido package, and put everything in the cliente package. It's a matter of taste.
  • As Thomas said, the Service interface must be available to your client code. So it must either be in the cliente package or the compartido package. But the ServiceAsync interface must be in the same package as the Service interface. And the ServiceAsync is certainly not something that is considered shared between cliente y servidor. Entonces el ServiceASync interface should be in the cliente paquete.
  • Como consecuencia, el Service interface is put in the cliente paquete.
  • En tu caso, el GWT Eclipse Plugin complained because the ServiceASync interface was not found in the Service paquete de interfaz.
  • Todavía puedes usar el compartido package for the classes that are sent through RPC.

Eso responde tu pregunta?

Respondido 29 ago 11, 11:08

Yes. Though given this explanation, I don't really see any useful conventions for what goes in the shared package. It would seem that RPC transfer objects would just as well go in client alongside the interfaces that use them. Perhaps the best convention for shared is for code that has legitimate server side uses even in the absence of a client. - Eric

Also - do you have a reference to the GWT documentation that states the above? In particular the first 3 bullet points? - Eric

Vea code.google.com/webtoolkit/doc/latest/… for the first 2 bullet points. For the third one, well, it's only a matter of how you build up your classpath. In my projects, my client código es no deployed on the server-side, only the shared one (I usually use 3 projects: shared, client y server; client y server Dependiendo de shared; I put client y shared in the classpath for the GWT DevMode and Compiler, and I deploy shared y server on the server; works best for medium/big projects) - Thomas Broyer

I guess that with Thomas details, you now have all the needed information ;-) - Pierre-Yves Ricau

Yes. I'd rather have a "non-shared" interface in shared than server-side code reference client. - Thomas Broyer

In my projects both Service y ServiceAsync tiene shared and everything works ok. Actually I don't see it any other way as SercviceImpl in server implementos Service interface and compiler needs to have them on the classpath.

Respondido 28 ago 11, 00:08

GWT-RPC generator uses a naming convention (sticking an Async suffix to the classname), adding a "package renaming rule" (Service in shared mientras ServiceAsync es en client) would like not fit with many people's package layout. So, the rule is that both interfaces are in the same package, whichever the name of the package, which allows you to put them in shared if you want (as Peter Knego said)

(that rule is also due to legacy, the shared convention has been introduced in GWT projects quite recently, comparatively with GWT-RPC)

Respondido 29 ago 11, 19:08

Service cannot go into server since it appears in the argument to the GWT.create(Service.class) llamada. - Eric

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.