CheerpJ Documentation

repository·main·Indexed 20 days ago

https://github.com/leaningtech/cheerpj-meta

A WebAssembly-based Java Virtual Machine that enables running Java 8, 11, and 17 applications, applets, and JNLP files directly in modern web browsers without plugins. It provides full Java SE support, including Swing/AWT, networking, and multi-threading, while allowing for seamless interoperability between Java and JavaScript.

Tokens
1.3K
Snippets
7
Records
15
Agent score
69%

What's inside CheerpJ

  1. Overview of CheerpJ features and capabilities

    main

    CheerpJ is a WebAssembly-based Java Virtual Machine (JVM) for the browser that provides a full runtime environment for Java 8, 11, and 17. It allows you to run Java applications, applets, and JNLP applications without browser plugins.

    Key Capabilities:

    • Run existing Java applications: Execute Java apps in the browser with no code changes.
    • Java Applets: Include legacy applets in modern webpages without plugins.
    • JNLP/Java Web Start: Migrate legacy Java Web Start applications to modern systems.
    • Java-JavaScript Interoperability: Use Java libraries in JS/TS and call JavaScript/DOM from Java.
    • Full Java SE Support: Includes support for Swing/AWT, Networking, a virtualized filesystem, Clipboard, Audio, and Printing.
    • Multi-threading: Supports Java multi-threading and concurrent applications via Web Workers.
  2. How CheerpJ works

    main

    CheerpJ functions through the combination of two primary components:

    1. Optimizing Java-to-JavaScript JIT compiler: Converts Java bytecode into highly optimized, garbage-collectible JavaScript.
    2. Full Java SE Runtime: A complete runtime environment based on OpenJDK (supporting Java 8, 11, and 17).

    Both components are written in C++ and compiled to WebAssembly and JavaScript using the Cheerp compiler.

  3. Run a Server-Client networking example with CheerpJ

    main

    This example demonstrates how to run two separate Java applications using CheerpJ that communicate with each other over a network.

    To implement this pattern, follow the step-by-step tutorial provided in the official CheerpJ documentation to set up the server and client environments.

    https://labs.leaningtech.com/cheerpj3/examples/serverclient
  4. Load the CheerpJ loader script

    main

    To use CheerpJ in your web application, you must include the loader script in your HTML. This script initializes the WebAssembly-based Java Virtual Machine environment in the browser.

    Note: The version in the URL (e.g., 4.3) should match the version of CheerpJ you intend to use.

    <script src="https://cjrtnc.leaningtech.com/4.3/loader.js"></script>