Create GWT applications on JBoss AS

This tutorial shows how to create Google Web Toolkit applications (GWT) using Eclipse and how to deploy them on WildFly. In the second part of this tutorial, we will show also how to interact with application server serices like RESTful Web services.

Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. A typical GWT application is composed of client and server resources. Client resources are used to create the front end layout using just Java classes (just like you would do with Swing). Server resources include RPC services which are implemented as Ajax calls.

Setting up GWT

Firstly, we recommend downloading the GWT SDK which is available at:

The SDK contains the core libraries, compiler, and development server that you need to write web applications.

Once unzipped the GWT, you will be able to create a basic application skeleton using the command webAppCreator. For example:

./webAppCreator -out MyWebApp com.mycompany.mywebapp.MyWebApp

Setting up the Project dependencies

The webappCreator uses Ant as project builder. If you are going to deploy your app on an application server, we recommend using Maven to build the project. You will need to set up the client and the server libraries.

In order to build the Client UI, you will need to include GWT libraries in it:


Then, in the dependencies, also include:


To build the Server side, include a Java EE or Jakarta EE compatible dependency:


Building the GWT User Interface

The User Interface of our application is minimal. We will add a Form which contains:

  • A Label
  • An Input field
  • A Button which triggers the REST Service

Here is the HelloWorldClient.ui.xml:

<ui:UiBinder xmlns:ui=''

  <g:HTMLPanel ui:field="root">
    <h1>GWT Hello World</h1>
    <form name="theForm" onsubmit="; return false;">
        <label for="name" id="name_label">Name</label> 
        <input name="name" ui:field="name" type="text" required="required" placeholder="Your Name"/>
        <g:Button ui:field="sayHelloButton" text="Say Hello"/><g:Label ui:field="result"/>


The UI is backed by the following

public class HelloWorldClient {

    interface MyUiBinder extends UiBinder<Panel, HelloWorldClient> {

    private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

    Panel root;
    Label result;
    InputElement name;
    Button sayHelloButton;

    HelloWorldClient() {
        sayHelloButton.getElement().setAttribute("name", "sayHelloButton");

    public void onButtonClick(ClickEvent e) {
        try {
            new RequestBuilder(RequestBuilder.GET, "hello/json/" + URL.encodePathSegment(name.getValue())).sendRequest(null,
                    new RequestCallback() {

                        public void onResponseReceived(Request request, Response response) {
                            if (response.getStatusCode() == Response.SC_OK) {
                                HelloResponse r = (HelloResponse) JsonUtils.safeEval(response.getText());
                            } else {
                                handleError("Server responded with status code " + response.getStatusCode());

                        public void onError(Request request, Throwable exception) {
        } catch (RequestException exception) {

    private void handleError(String details) {
        result.setText("Sorry, can't say hello now. " + details);

     * Returns the DOM fragment that this
     * @return
    public Panel getElement() {
        return root;


The most interesting part, is the onButtonClick which handles a click of the button by sending an AJAX request to the HelloWorldResource and then updating the label in response.

We also need a Class which maps the JSON response object sent back from the HelloWorldResource JAX-RS HelloWorldResource service.

public class HelloResponse extends JavaScriptObject {

    protected HelloResponse() {

    public final native String getResult() /*-{ return this.result; }-*/;


Finally, the GWT UI needs an Entry point which is loaded when the script is loaded in the Browser:

public class HelloWorldApp implements EntryPoint {

    public void onModuleLoad() {
        RootPanel.get().add(new HelloWorldClient().getElement());


Coding the Server side

Within the server folder, we will add a minimal REST Service which returns an XML or JSON String following up the GET Request:


public class HelloWorldResource {

    public String getHelloWorldJSON(@PathParam("name") String name) {
        System.out.println("name: " + name);
        return "{\"result\":\"" + "Hello " + name + "\"}";

    public String getHelloWorldXML(@PathParam("name") String name) {
        System.out.println("name: " + name);
        return "<xml><hello>" + name + "</hello></xml>";


Running the example

To build the application just run from the command line:

mvn clean install

Then, if you have included WildFly maven plugin, you can deploy the application automatically on the server with:

mvn wildfly:deploy

Otherwise, simply copy the WAR file in the deployments folder of the application server.

Finally, point the browser to the home page for the Web Context. For example, http://localhost:8080/jboss-helloworld-gwt/

gwt tutorial jboss wildfly


This article was a walkthough GWT. We have covered how to build a basic application which connects to WildFly using a REST endpoint.

Source code: