You don't have to learn JavaScript development stack

This tool will come in handy if you’re a Java developer who needs to write web front-end from scratch

Gabriela Motroc

© Shutterstock / Kosev

TeaVM, an ahead-of-time compiler of Java bytecode to JavaScript might come in handy if you’re a Java developer who needs to write web front-end from scratch. However, if you want to get your large existing codebase in Java or Kotlin and produce JavaScript, you’ve come to the wrong place.

What does your toolkit look like, Java developers? Here’s one more tool that could come in handy if you need to write web front-end from scratch. TeaVM is an ahead-of-time compile of Java bytecode and it’s capable of emitting JavaScript and WebAssembly.

Although its “close relative” is GWT, the difference is that “TeaVM relies on existing compilers, be it javac, kotlinc or scalac. These compilers produce bytecode (*.class or *.jar files), then TeaVM takes this bytecode and produces JavaScript code,” according to the project description.

If you are a Java (or Kotlin, or Scala) developer who used to write back-end code, TeaVM might be your choice. It’s true that a good developer (including Java developer) can learn JavaScript. However, to become an expert you have to spend a reasonable amount of your time.


You can use TeaVM if:

  • You are a Java developer and you are going to write web front-end from scratch.
  • You already have Java-based backend and want to integrate front-end code tightly into your existing development infrastructure.
  • You have some Java back-end code you want to reuse in front-end.
  • You are ready to rewrite your code to work with TeaVM.

SEE ALSO: Let it flow in Java

TeaVM benefits:

  • It tries to reconstruct the original structure of a method, so in most cases, it produces JavaScript that you would write manually. No bloated while/switch statements, as naive compilers often do.
  • It supports threads.
  • It is fast
  • It produces source maps; TeaVM IDEA plugin allows to debug code right from the IDE.

There’s also a subproject called Flavour.

What it is: a framework for writing single-paged web applications (you can use it together with your back-end code)

What it’s not: a server-side framework. You should write your back-end code using “normal” JDK like OpenJDK, Oracle JDK using your favorite frameworks.

The easiest way to run TeaVM is to use teavm-maven-plugin. Here’s an example

          <!-- This dependency is required by TeaVM to emulate subset of Java class library -->

If you want to learn how to get started with TeaVM, here’s how.

Gabriela Motroc
Gabriela Motroc was editor of and JAX Magazine. Before working at Software & Support Media Group, she studied International Communication Management at the Hague University of Applied Sciences.

Inline Feedbacks
View all comments