Then set your project properties, the module name will be the name of your eclipse project.
You should end up with the following project structure
and the following errors
Clean the maven project
We will not need the code that has been automatically generated so just keep your entrypoint and erase all the other classes.
Also clean your entrypoint.
Get rid of the errors
I hate errors, especialy in eclipse where I only want to see compile errors, so we will get rid of them. At this point you should only have one error. This error is due to the fact that the m2e maven eclipse plugin does not support all the plugin execution that are supported in maven. It is not a big deal. Just use quick fix ! Mark the goal as ignored for m2e inside eclipse.
Now you should not have any error. Nevertheless it is not finished yet. Let’s see if the server is running … Run as... Google application
Ok still some errors ! We need to clean the web.xml (src/main/webapp/WEB-INF/web.xml)
You can also delete the gwt module that was created with the tests gwtXXXJUnit.gwt.xml and remove the inherits to Junit inside your app.gwt.xml
Also clean your launch configuration and remove the reference to the gwtXXXJUnit module
Last but not least you can clean your html page.
Now clean and install your project
mvn clean install
We should be good to go now !
Implement a JAX-RS backend using Jersey
First we will need to add the dependency on JAX-RS API.
Then we need Jersey in our pom (The JAX-RS implementation). As of today, the latest version of Jersey is 2.7. As we are going to use an old version of Jetty, it does not implement the servlet 3.0 API so the dependency looks like this.
For our json processing we want to use Jackson so we also add the following dependency
Now we need to configure Jersey to listen to the api calls. To do, as we will use a servlet container that only supports 2.x servlets, we will use the Servlet 2.x configuration method. So in your web.xml you need to add the following lines. Other configuration options are possible depending on the servlet container you use (glassfish, tomcat etc…). Have a look to the jersey manual
Warning put the name of the package where you will put your resources. Here I use org.usesoft.gwtrestapp.server.interfaces.api where I will put all my resources classes.
Also you can see that my servlet mapping is the following /api/*. It means that jersey will intercept all the calls that looks like /api/something and will try to serve them with a resource defined in the package described aboved using the @Path param (see below for more info).
Writting your first resource
Below is an example of a Hello resource. I define its @Path as “hellos”. So everytime a call will look like /api/hellos this resource will be used to answer this call.
This resource returns some Hello object.
The corresponding Hello object. It is defined into the shared package to be accessible in the client and in the backend. Note that the jackson annotations are ‘codehaus’ one because restyGWT does not support ‘fasterxml’ version right now.
Now you can launch your GWT application. Call the following url:
It will answer
If you want to access a specific hello, call the following url:
It will answer
Implement a REST client using RestyGWT
Now it is time to code hour client with GWT and RestyGWT. It will see it will be very very easy !
Add RestyGWT dependency in your pom.
GWT module file config
Add RestyGWT to you GWT module file
Implement your client
We are going to define a rest interface so that RestyGWT will be able to generate the client code
Then to use the client, in the entry point I coded the following