Skip to content

Commit 3608df7

Browse files
committed
Write README
1 parent 10fdf45 commit 3608df7

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+
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)
70.6 KB
Loading

0 commit comments

Comments
 (0)