Skip to content

Commit 4e57ee2

Browse files
committed
Write README
1 parent 2264d57 commit 4e57ee2

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

native-image/wasm-javac/README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
11
# Compile `javac` to a Wasm Module
22

3-
TODO
3+
This demo illustrates how to use the WebAssembly backend of GraalVM to compile the `javac` tool into a Wasm module that can then run on the command-line or in the browser.
4+
5+
## Prerequisites
6+
7+
This demo requires:
8+
9+
1. An [Early Access Build](https://github.com/graalvm/oracle-graalvm-ea-builds) of Oracle GraalVM for JDK 25 or later.
10+
For example, using SDKMAN!: `sdk install java 25.ea.15-graal`
11+
2. The [Binaryen toolchain](https://github.com/WebAssembly/binaryen) in version 119 or later and on the system path.
12+
For example, using Homebrew: `brew install binaryen`
13+
14+
15+
## Run `javac` on Node
16+
17+
1. Build the Wasm module:
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 command generates a Wasm file and a corresponding JavaScript binding in the `target` directory.
23+
24+
2. Compile a Java file:
25+
```bash
26+
node target/javac.js HelloWasm.java
27+
```
28+
The resulting `HelloWasm.class` file is placed next to `HelloWasm.java`.
29+
This requires Node.js 22 or later.
30+
31+
## Run `javac` in the browser
32+
33+
1. Build the Wasm module:
34+
```bash
35+
mvn -Pjavacweb package
36+
```
37+
This command generates a Wasm file and a corresponding JavaScript binding in the `web` directory.
38+
39+
2. Run a local web server in the `web` directory:
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)
70.6 KB
Loading

0 commit comments

Comments
 (0)