Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do GWTRPC *Service Interface classes go in ".client" package instead of ".shared"?

Tags:

gwt

gwt-rpc

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

./client/GreetingService.java
./client/GreetingServiceAsync.java
./server/GreetingServiceImpl.java

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 and compiled into bytecode by javac

This would lead one to believe that code in client should not be on the compile-time sourcepath of javac. Yet since GreetingServiceImpl implements 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, the GWT Eclipse Plugin complains "Missing Asynchronous Interface"...

like image 785
Eric Avatar asked Dec 12 '25 06:12

Eric


1 Answers

Let's try to be clear :

  • There is no technical difference between the client and the shared package, it's only a matter of convention. Both are declared as source packages in your module (the .gwt.xml file)
  • client and shared package get both compiled into javascript and bytecode
  • On server side, the bytecode for the whole client part is usually available, although most of it is not used.
  • Therefore, some people just remove the shared package, and put everything in the client 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 client package or the shared 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 client and server. So the ServiceASync interface should be in the client package.
  • As a consequence, the Service interface is put in the client package.
  • In your case, the GWT Eclipse Plugin complained because the ServiceASync interface was not found in the Service interface package.
  • You can still use the shared package for the classes that are sent through RPC.

Does that answer your question?

like image 117
Pierre-Yves Ricau Avatar answered Dec 15 '25 07:12

Pierre-Yves Ricau