├── src └── main │ ├── webapp │ ├── index.html │ ├── output.html │ ├── output.js │ └── WEB-INF │ │ ├── faces-config.xml │ │ └── web.xml │ └── java │ └── local │ └── mitia │ ├── wasm │ └── WasmFunctions.java │ └── beans │ └── MainBean.java ├── README.MD └── pom.xml /src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/webapp/output.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # WebAssembly build from Java example 2 | 3 | A small demo to demonstrate how to build webassembly from java using *TeaVM* 4 | 5 | Following the presentation: 6 | https://speakerdeck.com/dalexandrov/webassembly-from-the-java-perspective 7 | 8 | Have fun! -------------------------------------------------------------------------------- /src/main/java/local/mitia/wasm/WasmFunctions.java: -------------------------------------------------------------------------------- 1 | package local.mitia.wasm; 2 | 3 | import org.teavm.interop.Export; 4 | 5 | /** 6 | * Created by Dmitry Alexandrov on 25.01.19. 7 | */ 8 | public class WasmFunctions { 9 | 10 | @Export(name = "thePurposeOfLife") 11 | public static int getThePurposeOfLife(){ 12 | return 42; 13 | } 14 | 15 | public static void main(String[] args) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/webapp/output.js: -------------------------------------------------------------------------------- 1 | if ('WebAssembly' in window) { 2 | // Set the import object in instantiateStreaming 3 | WebAssembly.instantiateStreaming(fetch('wasm/classes.wasm')) 4 | .then(result => { 5 | 6 | //the Purpse of Life is: 7 | result = result.instance.exports.thePurposeOfLife(); 8 | document.getElementById('wasm').innerHTML = 9 | 'The Purpose of life according to teavm wasm from java: ' + result; 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/local/mitia/beans/MainBean.java: -------------------------------------------------------------------------------- 1 | package local.mitia.beans; 2 | 3 | import javax.faces.bean.ManagedBean; 4 | import javax.faces.bean.SessionScoped; 5 | 6 | @ManagedBean(name = "mainBean") 7 | @SessionScoped 8 | public class MainBean { 9 | 10 | private String inputText; 11 | 12 | public String getInputText() { 13 | return inputText; 14 | } 15 | 16 | public void setInputText(String inputText) { 17 | this.inputText = inputText; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/faces-config.xml: -------------------------------------------------------------------------------- 1 | 2 |