Knowledge Seeking

GWT- Time to Refactor means Async Interfaces Issue April 7, 2011

Filed under: GWT,Java — nicozan @ 4:43 pm
Tags: , , , ,


When you first create a GWT App, the project is divided ,usually, into three packages: client,shared and server. In this post we’ll consider the next packages names:

Refactoring Services

Let’s consider that in the package com.wordpress.nicozan.client we have the interface bankService and we have too the interface bankServiceAsync. This Async-interface help us to communicate with the server side of our application. The server side is in the package com.wordpress.nicozan.server and contains an implementation named bankServiceImpl.
Up to now everything seems nice and simple, but if your application starts to grow and improve, you’ll probably have many services. This means that your client package we’ll have several service interfaces mixed with your widgets and utility classes.
So to avoid having everything mixed up, you decide to create the next packages:

This post will focus in the services package. Inside this package we’ll put the service interfaces that are related to the Async interfaces.
At the moment we compile (mvn clean install ), an error will appear. The error will say that the Async interfaces cannot be found. This problem is because by default the gwt-maven-plugin generates the Async interfaces from the service interfaces located in the client package, and it doesn’t look inside the client sub-packages. The way to solve this problem is by adding 2 tags to the plugin configuration inside the pom.xml:

<!-- GWT Maven Plugin -->
       <!-- Plugin configuration. There are many available options, see
         gwt-maven-plugin documentation at -->

In the code snippet above, the two important tags are servicePattern and inplace. In the first one, we specify a relative path to where service interfaces are. The second tag, specifies that the generated Async interface have to be located in the same package as its analog service interface.