Пример кода Java < /p>
package com.lson;
import org.teavm.jso.JSExport;
public class JsTest {
private static JsTest instance = new JsTest();
public static void main(String[] args) {
add(1, 2);
}
@JSExport
public static JsTest getInstance() {
return instance;
}
@JSExport
public static int add(int a, int b) {
int i = a + b;
System.out.println("add:" + i);
return i;
}
@JSExport
public int multiply(int a, int b) {
int i = a * b;
System.out.println("multiply:" + i);
return i;
}
}
< /code>
плагин Maven < /p>
org.teavm
teavm-maven-plugin
0.12.0
org.teavm
teavm-classlib
0.12.0
compile
process-classes
com.lson.JsTest
true
true
true
false
org.teavm:teavm-jso:0.12.0
WEBASSEMBLY
Затем выполнить пакет MVN . Создаются следующие файлы: < /p>
[*]classes.wasm
[*]classes.wasm.c
[*]classes.wasm-Runtime.js
[*]classes.wastclasses.wast
Следующая ошибка будет выведена в консоли: < /p>
wasm2.html:10 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'load')
at main (wasm2.html:10:42)
at onload (wasm2.html:17:24)
Подробнее здесь: https://stackoverflow.com/questions/796 ... use-in-web