Osman Recai Ödemis
Blog about digital transformation

Blog about digital transformation

Don't use GWT or Google Web Toolkit ?

Osman Recai Ödemis's photo
Osman Recai Ödemis
·Nov 2, 2021·

4 min read

Hello folks how are you ?

Today I want write about maybe the forgotten web framework from Google - Google Web Toolkit or GWT. Attention by forgotten I mean, we don't see news about GWT every day on hackernews but it is used under oldschool Java devs and enterprises 😃

History of GWT

GWT is developed by Google in 2006 where Single Page Applications (SPA) or AJAX intensive apps become very popular. Google Docs, Google Mails .. all these web-apps are SPAs and must behave like desktop apps in browsers.

Back then it was very challenging to develop maintainable JavaScript software architectures with frameworks like JQuery. On the other side programming languages like Java or C# has very prooven history in backend development for creating maintainable code. We have design patterns to produce effective architectures. The solution from Google in 2006: creating frontend architectures with Java 🚀

Idea of GWT

We develop our web apps in Java ⛏️. If you are already Java dev switching to frontend back than was very easy. Google Web Toolkit has built in compiler, which compiles your Java code in JavaScript.

The basic idea is like NodeJs web frameworks like Express, we develop our backend and frontend parts in Java - We are Fullstack developers 🚀

For example this code produces a button in the browser and if you click you receive a nice alert message:

@Override
    public void onModuleLoad() {
        Button button = new Button("Click me");
        button.addClickHandler(clickEvent -> {
            Window.alert("Hello World from Java!");
        });

        RootPanel.get("helloButton").add(button);
    }

UI Libs

In modern web dev we can pick up some UI components from Bootstrap or Bulma. There are tons of UI libs for public use.

In GWT we have the standard gwt-widget library from Google and very old dated framework like GXT. The disadvantage of this approach is, Its very hard to make it modern look with CSS and not implements the modern HTML5 approach. Another modern approach is DominoKit , I highly recommend it If you want go with GWT.

How to start with GWT

If you visit the website of GWT, maybe you see in the getting started sections commands like 😟:

ant devmode

Come on ... I personally don't use ant build, we have in modern Java ecosystem build tools like gradle or maven. Instead use this site only for documentation.

If you want start very quickly with GWT, please go to this repo with samples and starters. You need maven and start your IDE 🚀.

Please give the this project on Github star, its actually very awesome to start quickly with GWT.

2021, 2022, ... ?

In June 2012, Google handed control to the steering committee, to make GWT more visible in open source community.

Ok but we are already in 2021 and you can read on news or social media GWT is dead. They are right, GWT 2 is dead. But it means not that the framework is not more developed, it is heavily developed. The new approach uses different compiler named J2CL by Google and the community makes GWT APIs J2CL compatible with version GWT 3.0.

The difference between J2Cl and old compiler from GWT 2.* is that J2Cl is only a transpiler, which transpiles your Java code in Closure style JavaScript.

From programming perspective it changes nothing, the APIs are ported further and you can develop further you web apps in Java. But the toolchain is more slim.

Why Java in Frontend ? We have frameworks like Vue, React or Svelte .. 🚀🚀🚀

From my perspective developing web apps in Java must be evaluated before the project starts. Following points are very important to choose GWT.

  • you are already experienced Java dev
  • you don't plan to use complex JavaScript frameworks dependency for your app
  • BUT some Js Frameworks are ported to GWT 😃 google it like VueGWT but not the full specification of Vue
  • you have minimal CRUD app with simple UI components

If you break the requirements the code can be very challenging over time, there is also a JsInterop Specification from Google where you can bind any JS-Framework like VueJs in GWT, but it becomes very challenging in maintainability over long time.

And why you must port it to Java ???? If you have an awesome Js-Framework 😃

But if you are experienced oldschool Java dev and need an small web app with not to much fancy UI requirements go with GWT.

Conclusion

We read news about WASM and polyglot architectures for web apps in languages other than JavaScript like Elm. Maybe in some years also GWT becomes again popular under the top news.

But the lack of documentation, examples and small community makes it very difficult to switch to GWT. There are two awesome gitter channels vertispan and gwt where GWT experts talking every day on problems and ideas please look if you are interested.

Please give me feedback if you use GWT in your projects

Happy coding 😃

 
Share this