Tom
Tom

Reputation: 934

How to generate .wasm file or .wast file from java source code?

How I can generate .wasm file or .wast file for the following code:

import java.util.ArrayList;
public class NewClass2
{
    public static void main(String[] args)
    {
        ArrayList<String> lis = new ArrayList<>();
        lis.add("My");
        lis.add("Name");
        System.out.println(lis.get(2));
    }
}

Can anyone help me in this regard? I have check TeaVM, CheerpJ, etc, but unable to find to get generate web assembly code.

Upvotes: 1

Views: 387

Answers (1)

sbc100
sbc100

Reputation: 3032

While one could, in theory, write a compiler from JavaScript to WebAssembly, converting JavaScript to WebAssembly is not currently possible or something that WebAssembly was explicitly designed for. If you want to write code that looks somewhat like JavaScript, but targets WebAssembly, the closest thing today is probably AssemblyScript: https://www.assemblyscript.org/.

Upvotes: 1

Related Questions