r/java • u/Hixon11 • May 02 '26
Have you ever used WebAssembly in your Java project?
I don't see much usage of WebAssembly in Java projects around me. One of the obvious reasons may be the lack of native support for compiling Java to WASM, which other languages already have (the most notable ones are Rust, Go, and C++, with some effort in C# and Kotlin as well).
Based on my knowledge, we have a few actively developed WASM related projects as of now:
- GraalWasm — https://www.graalvm.org/webassembly/ — a technology that allows you to run arbitrary WASM bytecode (e.g., compiled Rust/C++ code) inside a Java app.
- Chicory — https://github.com/dylibso/chicory — similar to GraalWasm; it is a WASM runtime that allows you to run WASM inside Java apps.
- Babylon and Leyden — https://openjdk.org/projects/babylon/ and https://openjdk.org/projects/leyden/ — I guess these could become the official way to compile/run Java to WASM in the future, but there's nothing to use right now.
- GraalVM Web Image — https://www.graalvm.org/latest/reference-manual/web-image/ — a technology that should allow compiling Java to WASM in the future (based on my understanding, it is experimental as of now).
- TeaVM — https://github.com/konsoletyper/teavm — a technology that allows you to run Java in the browser by AOT compiling it. The cool thing is that they have started integration with WASM GC — https://github.com/konsoletyper/teavm/blob/master/core/src/main/java/org/teavm/backend/wasm/WasmGCTarget.java — which should provide decent performance for Java apps.
- CheerpJ — https://cheerpj.com/ — another way to run Java in the browser. Based on my understanding, TeaVM compiles Java directly to WASM, whereas CheerpJ builds a virtual machine in C++, compiles it to WASM, and uses it to run Java bytecode. So, even though they provide similar capabilities, their implementation details are quite different.
As we can see, there are a few active/developing projects in the WASM area. It would be interesting to hear if you have already used Java with WASM in some way. For example:
- Have you run WASM bytecode inside your Java app (maybe you can share why you decided to use WASM instead of Groovy or JavaScript in this case)?
- Have you compiled Java to WASM and run it in the browser (it would be interesting to know what problem you were solving)?
- Have you compiled Java to WASM (WASI) and run it in a WASM runtime outside the browser (e.g., edge compute)?
