├── 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 | 6 | 7 | 8 | 9 | * 10 | 11 | 12 | nextPage 13 | /views/secondPage.xhtml 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Faces Servlet 8 | javax.faces.webapp.FacesServlet 9 | 1 10 | 11 | 12 | Faces Servlet 13 | *.xhtml 14 | 15 | 16 | 17 | index.html 18 | 19 | 20 | 21 | wasm 22 | application/wasm 23 | 24 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | local.mitia 8 | wasmJava 9 | 0.5.1 10 | war 11 | 12 | 13 | 14 | 1.8 15 | https://oss.sonatype.org/content/repositories/snapshots/ 16 | false 17 | 1 18 | true 19 | 20 | 21 | 22 | 23 | sonatype-nexus-snapshots 24 | Sonatype Nexus Snapshots 25 | ${sonatypeOssDistMgmtSnapshotsUrl} 26 | 27 | 28 | sonatype-nexus-staging 29 | Nexus Release Repository 30 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 31 | 32 | 33 | 34 | 35 | 36 | 37 | javax.faces 38 | javax.faces-api 39 | 2.1 40 | provided 41 | 42 | 43 | 44 | org.primefaces 45 | primefaces 46 | 6.0 47 | 48 | 49 | 50 | 51 | commons-io 52 | commons-io 53 | 2.4 54 | 55 | 56 | org.apache.maven 57 | maven-plugin-api 58 | 3.3.3 59 | 60 | 61 | org.apache.maven.plugin-tools 62 | maven-plugin-annotations 63 | 3.3 64 | 65 | 66 | org.apache.maven 67 | maven-core 68 | 3.3.3 69 | 70 | 71 | org.apache.maven 72 | maven-artifact 73 | 3.3.3 74 | 75 | 76 | org.apache.maven.plugins 77 | maven-shade-plugin 78 | 3.1.1 79 | 80 | 81 | 82 | 83 | org.teavm 84 | teavm-classlib 85 | ${project.version} 86 | 87 | 88 | org.teavm 89 | teavm-jso-apis 90 | ${project.version} 91 | provided 92 | 93 | 94 | org.teavm 95 | teavm-interop 96 | ${project.version} 97 | 98 | 99 | org.jbox2d 100 | jbox2d-library 101 | 2.2.1.1 102 | 103 | 104 | org.jbox2d 105 | jbox2d-library 106 | 2.2.1.1 107 | sources 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | maven-war-plugin 116 | 2.4 117 | 118 | 119 | 120 | ${project.build.directory}/generated/wasm 121 | 122 | 123 | false 124 | 125 | 126 | 127 | 128 | org.teavm 129 | teavm-maven-plugin 130 | ${project.version} 131 | 132 | 133 | wasm-client 134 | 135 | compile 136 | 137 | 138 | ${project.build.directory}/generated/wasm/wasm 139 | local.mitia.wasm.WasmFunctions 140 | true 141 | WEBASSEMBLY 142 | FULL 143 | 8 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-source-plugin 153 | 154 | 155 | org.apache.maven.plugins 156 | maven-javadoc-plugin 157 | 158 | 159 | 160 | 161 | 162 | --------------------------------------------------------------------------------