Home / Java Patterns and Pitfalls     frequal.com

Single-Page Apps Make Java Fun Again

Java used to be fun. You could write your code, it ran everywhere, even in the browser. You could make animations, games, chat apps, and more. It was all new and exciting.

As time went by, the promise of Java held true. Code you wrote kept on working. Applets you wrote worked years later. Web Start came along and let you deploy desktop apps easily via the web.

Then the browser vendors turned on Java. Whether it was Google looking for payback against Oracle for their Java lawsuit, or Mozilla promoting their homegrown JavaScript, browsers one by one blocked Java. For the first time the availability of Java to consumers began to shrink.

A New Hope

Around the time things started looking bleak for mass distribution of Java-based apps, TeaVM appeared on the scene. A technology for compiling Java bytecode to JavaScript, it lets Java developers deploy code in the browser using familiar tools. The developer of TeaVM (Alexey Andreev) realized a Java-friendly framework for building single-page apps was needed, so he implemented one on top of TeaVM and called it Flavour.

The Development Experience

For Java developers, your familiar tools now can build true modern web apps. You can develop in your IDE of choice. Autocomplete and other editing shortcuts work well with TeaVM's JSO APIs, so you can write code for the browser but leverage the power of a strongly-typed development environment.

Once built, the application is in the target folder, like any maven app. Since the content is HTML plus a single JS file, you can open it in a browser, and refresh after builds to see the latest version of the code.


TeaVM produces a WAR file, so you can deploy it in an app container like any other Java web app. However, at its core your app is an HTML file, a classes.js file, and (optionally) an app.css file. you can simply copy those files to a public folder on any web server and your app is deployed.

Once deployed, anyone in the world can run your app by typing on the URL. No downloading an app, no installer, no app store, just visit a web page.

Bringing the Joy Back To Java

TeaVM makes developing Java front-ends fun. The development process is familiar and easy. Deployment is a piece of cake. And users can access your app from any device. Write Once, Run Anywhere? Yes! Java the way it was meant to be.
Last modified on 16 Feb 2021 by AO

Copyright © 2024 Andrew Oliver