Don't use GWT or Google Web Toolkit?

Don't use GWT or Google Web Toolkit?

Hello folks how are you?

Today I want to 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 when 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# have a very proven 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 was very easy. Google Web Toolkit has a 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 a modern look with CSS and not implement the modern HTML5 approach. Another modern approach is DominoKit, I highly recommend it If you want to 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 to start very quickly with GWT, please go to this repo with samples and starters. You need maven and start your IDE 🚀.

Please give this project on Github star, it's 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 the 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 a different compiler named J2CL by Google and the community makes GWT APIs J2CL compatible with version GWT 3.0.

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

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

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. The following points are very important to choose GWT.

  • you are already an 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 a 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 a long time.

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

But if you are an experienced oldschool Java dev and need a small web app with not too many 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 talk every day about problems and ideas please look if you are interested.

Please give me feedback if you use GWT in your projects

Happy coding 😃