Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Compile javac into a Wasm Module

This demo illustrates how to use the new experimental WebAssembly backend for GraalVM to compile the javac tool into a Wasm module that can then run on the command-line or in the browser. Check out the live demo here.

Prerequisites

This demo requires:

  1. Oracle GraalVM for JDK 25 or later. For example, using SDKMAN!: sdk install java 25.0.1-graal
  2. The Binaryen toolchain in version 119 or later and on the system path. For example, using Homebrew: brew install binaryen

Run javac on Node

  1. Build the Wasm module with the native profile:

    $ ./mvnw -Pnative package

    The demo uses the Native Build Tools for building native images with GraalVM and Maven. This command generates a Wasm file and a corresponding JavaScript binding in the target directory.

  2. Compile a Java file:

    node --experimental-wasm-exnref target/javac.js HelloWasm.java

    The resulting HelloWasm.class file is placed next to HelloWasm.java. This requires Node.js 22 or later. The --experimental-wasm-exnref option is no longer required with Node.js 25 or later.

Run javac in the Browser

  1. Build the Wasm module with the javacweb profile:

    ./mvnw -Pjavacweb package

    This command generates a Wasm file and a corresponding JavaScript binding in the web directory.

  2. Run a local web server in the web directory:

    cd web
    jwebserver

    This will serve the web directory locally on port 8000.

  3. Navigate to http://localhost:8000 to compile Java programs and disassemble JVM bytecode in the browser: