File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Compile ` javac ` to a Wasm Module
2
2
3
- TODO
3
+ In this example, we'll compile the ` javac ` tool to Wasm modules that can then run on the commandline or the browser.
4
+
5
+ ## Prerequisites
6
+
7
+ These examples require:
8
+
9
+ 1 . An [ Oracle GraalVM Early Access Build] ( https://github.com/graalvm/oracle-graalvm-ea-builds ) , version 25.0.0-.ea.15 or later.
10
+ For example, using SDKMAN!: ` sdk install java 25.ea.15-graal `
11
+ 2 . The [ Binaryen toolchain] ( https://github.com/WebAssembly/binaryen ) on the sytem path, version 119 or later
12
+ For example, using Homebrew: ` brew install binaryen `
13
+
14
+
15
+ ## Run ` javac ` CLI
16
+
17
+ 1 . Build the Wasm binary:
18
+ ``` bash
19
+ mvn -Pnative package
20
+ ```
21
+ Uses the [Native Build Tools](https://graalvm.github.io/native-build-tools/latest/index.html) to run the ` native-image` executable from Maven.
22
+ This will generate the Wasm file and its JavaScript wrapper in the ` target` directory.
23
+
24
+ 2. Compile a Java file:
25
+ ` ` ` bash
26
+ node target/javac.js HelloWorld.java
27
+ ` ` `
28
+ The resulting ` HelloWorld.class` file is placed next to ` HelloWorld.java` .
29
+ This requires Node.js 22 or later.
30
+
31
+ # # Run Web Demo
32
+
33
+ 1. Build the Wasm binary:
34
+ ` ` ` bash
35
+ mvn -Pjavacweb package
36
+ ` ` `
37
+ This generates the Wasm and JS files into the ` web` directory.
38
+
39
+ 2. Host Web Server:
40
+ ` ` ` bash
41
+ cd web
42
+ jwebserver
43
+ ` ` `
44
+ This will serve the ` web` directory locally on port ` 8000` .
45
+
46
+ 3. Navigate to http://localhost:8000 to compile Java programs in the browser:
47
+ ! [](images/screenshot.png)
You can’t perform that action at this time.
0 commit comments