Skip to main content

Command Palette

Search for a command to run...

Don't use GWT or Google Web Toolkit?

Updated
4 min read
Don't use GWT or Google Web Toolkit?
O

I'm Osman Recai Ödemis working as a a consultant. I'm interested in the fields of Software Engineering, IoT, AI.

Nice to meet you :)

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 😃

S

Interesting. When we started Codename One we wrote the UI for the web interface in GWT. It was awesome to work with but it was hard getting the "native" stuff working. E.g. mixing in custom JavaScript and getting the CSS look and feel right. Eventually we moved to bootstrap for the UI and now use Codename Ones JavaScript port for the UI.

We use react on typescript in Lightrun and it's an absolute pain for me personally. But it does have the advantage of wide skill set in terms of hiring. That's basically what it comes down to. I wish technologies like GWT would get better PR and traction but I'm not sure how we can get there.

2
A

With the new GWT now mixing both echosystems -Java and JavaScript- have never been this easy, Now we can have the best of the two worlds without sacrificing anything, with how JsInterop has evolved and the elemental2 libraries and other alternatives that barrier has long gone.

Now in GWT are talking the browser API we can mix html native elements with our own developed custom element seamlessly, we use the browser native APIs.

We have tools that allows us to share lots of our code between backend and frontend, we have excellent type checking, we have strong contracts, and awesome IDEs.

In DominoKit we took one step further and decided to build a full modern stack that cover most of the areas for building a modern web application :

Domino-ui : https://github.com/DominoKit/domino-ui Very rich easy to use UI library with a good look and feel that uses html native elements and API.

Domino-jackson : https://github.com/DominoKit/domino-jackson JSON (de)serializers for Java objects that uses jackson style and annotations, The same mapper works on the browser and the JVM, and support a very wide set of Java data types.

Domino-rest : https://github.com/DominoKit/domino-rest Generate REST clients from jax-rs interfaces shared between frontend and backend.

Domino-history : https://github.com/DominoKit/domino-history Manipulate the browser URL with an easy to use API and listen to the URL changes, routing have been this easy.

Domino-aggregator : https://github.com/DominoKit/domino-aggregator Wait for different async tasks to complete before doing some action.

Domino-slf4j-logger https://github.com/DominoKit/domino-slf4j-logger slf4j logging right in the browser.

Domino-mvp : https://github.com/DominoKit/domino-mvp Light-weight but rich and comprehensive flexible MVP framework to control your application screens life-cycle

And if this is not enough, the community has a lot more to add, even Java itself is getting better and we are keeping up.

For the hiring part I think that is one point that need to solve, nowadays what we need is not a GWT expert, all you need is a java developer with little html and css knowledge, GWT is not just a compiler, just like TypeScript it is just the echo-system around it.

1
S

That's really impressive stuff you did there. I might try it in an upcoming project as I'm really dreading the react nonsense.

Is there a business model behind this or something you plan on launching?

The hiring portion isn't so much something I would say... I agree. But I hear that nonsense from people who have doubts about Codename One.

1
O

Thank you very much Shai Almong (@talktotheduck) for sharing your experience.

As Ahmad Ahmad K. Bawaneh said JsInterop and elemental2 libs make it possible to share and mixing Js and Java. Domino demonstrates this approach very good, also the framework VueGWT( https://vuegwt.github.io/vue-gwt/) uses this mixin approach. But again I think it must be accessible to wide are of developers to test it more and more in different Use Cases. Frameworks like React are heavly used in daily dev as we can see articles on top news.

Thanks

1
A

Shai Almog Yes, We have big plans for this, we love open source and we will keep providing open source version of our tools, we are currently working on website and actually going through the official DominoKit company registration, we plan to extend and expand our tools and the features they provide.

Our goal is to be the #1 target for java developers in this area.

2
S

Ahmad K. Bawaneh congratulations and best of luck to you guys!

If you need to pick my brain feel free to write to me. I've done a lot of work in this field. Specifically open source, community building and trying to commercialize a free product. That's pretty hard, especially when you're dealing with entrenched competition and historic perception.

2
A

Thank you for this article, I am the author of @dominokit which domino-ui is part of, I am using GWT in a big project, 264+ screens, around 100K LoC, running in production in 14+ sites, The team started with 2 developer working on both frontend and backend, then reduced to 1 developer since it was enough to keep up with a 10+ backend developers adding features to the application.

We have great look and feel UI, excellent performance, the is compiled and jzipped on the wire to just 800KB, and most important excellent maintainability, we can get any #java developer to ride in in few hours when we want.

GWT have never been dead, we got version 2.9 recently with java 11 support, and 2.10 is coming very soon, and after that we are doing java 17 support and add language features. we already implemented some thanks to Colin Alworth.

The community around GWT despite being small but it is a very active community, try to ask a question in the gitter channels or in the google group and see how fast you will get the answer.

The tools and frameworks around it have also been under heavy active development, those are modern tools and frameworks that covers almost every aspect if web development, and you get it all with one stack, Java.

1
O

Thank you very much Ahmad K. Bawaneh (Ahmad K. Bawaneh) for your commitment to the GWT ecosystem and sharing your intellectual ideas and experiences with us. I appreciate your work in the community. Its very fascinating how the community develops fast.

I think if we write more blogs and tutorials and sharing the ideas, GWT becomes again popular under the new generation web developers.

Thanks lot

1