Paul Verest
Paul Verest

Reputation: 64022

How to compile Java to WASM (WebAssembly)?

I wonder can I use Java and compile it to WASM (WebAssembly)?

The list https://webassembly.org/getting-started/developers-guide/ has no Java, Kotlin


GraalVM WASM project https://www.graalvm.org/reference-manual/wasm/ is for running wasm inside JVM, not for running Java projects within WebAssembly.

Upvotes: 52

Views: 42888

Answers (2)

Technosophos
Technosophos

Reputation: 561

Running Java bytecode inside of a Wasm runtime is possible a few ways. One is to use TeaVM. This page tracks the progress of various methods: https://www.fermyon.com/wasm-languages/java

Upvotes: 4

Tristan F.-R.
Tristan F.-R.

Reputation: 4224

Here are a few compilers that can do this for you:

https://github.com/konsoletyper/teavm (most popular & my own reccomendation: https://teavm.org/)

https://github.com/i-net-software/JWebAssembly (only to webassembly, the others can do webassembly and javascript)

https://github.com/mirkosertic/Bytecoder

https://github.com/leaningtech/cheerpj-meta

Do note, that all of them have their limitations, most commonly that every Java class in Java's standard library won't work well with it (for example, TeaVM and others have problems with reflection).

They also require pipeline integration -- make sure to be using a build tool these compilers support, such as gradle or maven

Upvotes: 17

Related Questions