如何将 Java 编译为 WASM(WebAssembly)?

我想知道我可以使用 Java 并将其编译为 WASM(WebAssembly)吗?

列表 https://webassembly.org/getting-started/developers-guide/ 没有 Java、Kotlin


GraalVM WASM 项目 https://www.graalvm.org/reference-manual/wasm/ 用于在 JVM 中运行 wasm,而不是用于在 WebAssembly 中运行 Java 项目。

stack overflow How to compile Java to WASM (WebAssembly)?
原文答案

答案:

作者头像

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