Java in WebAssembly

Many exciting WebAssembly things are happening in the Java ecosystem. There are a few projects that are rapidly maturing, and that can generate browser-oriented JS.

The various projects handle memory management differently. Their feature sets also differ.

Uses

All of the existing Java implementations are browser oriented, and are designed to let developers write Java and link to it from JavaScript.

Available Implementations

There is a working Wasm plus WASI version of TeaVM that allows you to run Java apps in Spin and other WASI-compliant runtimes (like WasmTime).

Here’s a detailed video by Joel Dice:

  • The Bytecoder project cross-compiles Java to WebAssembly that can be executed in the browser
  • The TeaVM project has experimental support for browser-based WebAssembly
  • A dedicate WebAssembly compiler called JWebAssembly can translate any JVM bytecode to WebAssembly, including Groovy, Clojure, and Kotlin. It, too, is browser-centric.
  • CheerpJ is much more ambitious, handling the UI as well

Learn More

Here are some great resources: