Skip to content

Latest commit

 

History

History
72 lines (53 loc) · 2.12 KB

README.md

File metadata and controls

72 lines (53 loc) · 2.12 KB

java-web

A JVM written in TypeScript that runs Java 25 class files and JARs in the browser and under Node. It runs the real OpenJDK 25 class library unmodified, and its page API matches CheerpJ's, so existing pages can switch.

Use it in a page

pnpm add @project516/java-web

Serve node_modules/@project516/java-web/dist/ as static files (on a GitHub Pages project site, /app/ is the site root user.github.io, so the page's files are under /app/<repo>/), then:

<script src="java-web.js"></script>
<pre id="console"></pre>
<script type="module">
  await cheerpjInit();
  await cheerpjRunJar("/app/my-app.jar");   // /app/ is the web server root
</script>

cheerpjRunMain, cheerpjRunLibrary (call Java from JS), JS natives and /files/ storage work too. See docs/browser.md.

Use it under Node

npx @project516/java-web -cp classes Main          # or: npx @project516/java-web -jar app.jar
import { runNode } from "@project516/java-web";
const code = await runNode({ classpath: ["classes"], mainClass: "Main" });

See docs/node.md.

What runs

  • Console apps, libraries and javac: every Java SE module, plus jdk.compiler, jdk.httpserver and a few more.
  • The headless parts of java.desktop, including Graphics2D on a BufferedImage, with HotSpot's pixels except for text.
  • Sockets: real ones under Node; in the browser, loopback inside the VM and http:/https: through fetch.
  • Child processes under Node, through the host's own programs.
  • Not yet: AWT and Swing windows, child processes in the browser, IPv6.

Details: docs/support.md.

Develop

You need Node 23.6+, pnpm, curl and bzip2 on Linux or macOS.

pnpm install
pnpm jdk          # downloads the pinned JDK 25 and builds the image
pnpm test         # compares programs against HotSpot
pnpm build        # builds dist/

More: docs/development.md.

License

AGPL-3.0-only. The OpenJDK class library is GPL-2.0 with the Classpath Exception, and the bundled DejaVu Sans font has its own license; both notices ship in dist/jdk/legal/.