Published in


CheerpJ 2.0 released — now with WebAssembly support

Compile Java applications into WebAssembly and JavaScript

Example Java application converted to WebAssembly and JavaScript with CheerpJ (OpenAstexViewer)
  1. Covering 100% of the Java 8 language, including reflection and dynamic class generation;
  2. Providing a full Java SE runtime library;
  3. Supporting file system access (read and write), audio, printing through native browser features;
  4. Supporting Java multi-threading and HTML5 WebWorkers;
  5. Converting Java from bytecode, without requiring access to the application source code.

How does CheerpJ work?

CheerpJ consists of three components: an AOT compiler, a full Java runtime in WebAssembly and JavaScript, and an interoperability API.

  1. A complete, modular, optimised Java 8 SE runtime library in WebAssembly and JavaScript;
  2. A module to allow transparent support for reflection and dynamic class generation;
  3. Browser-based implementations of the file system, audio, printing, and other ‘operating system’ features.
  1. Access and manipulation of the DOM from Java;
  2. Implementation of ‘native’ Java methods in JavaScript;
  3. Access to converted Java libraries from HTML5/JavaScript.

How do I use CheerpJ?

Using CheerpJ to convert your Java application is straightforward:

  • Compile all your .jar archives using the CheerpJ AOT compiler;
  • Minimise your .jar archives (optional, removes all the Java bytecode from the packages);
  • Embed your converted application (or link, if a library) in a HTML page, and link to the CheerpJ runtime library.

The CheerpJ runtime environment

CheerpJ includes a full Java 8 SE runtime environment, plus a collection of browser-based ‘native’ implementations of different functionalities.

  1. Virtual file systems implemented on top of IndexedDB (read-write access), HTTP(S) (read-only) and strings (read-only);
  2. Support for real-time audio (via WebAudio);
  3. Support for printing (via the browser printing dialogue);
  4. Support for WebWorkers, allowing the development of concurrent applications;
  5. Support for DOM manipulation, as well as invoking JavaScript from Java.

Why CheerpJ?

CheerpJ was developed with three main use-case scenarios in mind:

  1. The conversion of legacy Java applications and Java Applets to HTML5 with minimal or no effort, to extend their life until deprecation, or until a replacement native HTML application has been developed;
  2. The migration of an existing Java client to a browser-based web application, usually by converting the business logic from Java to WebAssembly/JavaScript with CheerpJ, and rewriting the UI in native HTML;
  3. Using (converted) Java libraries as part of a native web application.

CheerpJ and performance

BlackBird, a cloud and browser-based video editor made with CheerpJ.
  1. Modularised Java 8 runtime. Only the required components of the runtime are downloaded, to minimise the total download footprint. A special debugging feature allows tracking the methods originating the request of each runtime module, to allow further optimisations on the application side.
  2. Highly-optimised code generation, based on LLVM full-code optimisations. CheerpJ is a full compiler based on LLVM, and as such, it leverages all the full-code optimisations of the LLVM compiler stack.
  3. Removal of bytecode from .jar archives. CheerpJ requires the original .jar archives to be deployed alongside the application to support reflection and dynamic class generation. However, only the archive structure and metadata are preserved, significantly minimising the download size.

Full Changelog — CheerpJ 2.0

CheerpJ Runtime

  • Introduction of WebAssembly runtime modules to improve runtime speed and reduce the size of packages with heavy computational cost (e.g. font rendering)
  • Extended file system support to read, write and delete (IndexedDB backend)
  • New read-only filesystem in /str/ for Strings or binary data
  • Improved event handling, mouse interaction and focus
  • Extend support for charsets

CheerpJ AOT compiler

  • Improved robustness to invalid classes often present in real-world JAR archives
  • Improved isolation of CheerpJ symbols to avoid collisions with JavaScript identifiers in real-world HTML pages (particularly important if used in a front-end framework such as Angular or React)
  • Improved support to multi-threading, in particular Thread.interrupt
  • Use the CFGStackifier algorithm to synthesize control flow in generated code

Integration APIs and interoperability

  • New API to receive preloading notification (allows to build custom progress bars)
  • Improved detection of Applets on HTML pages
  • Improved packaging for MacOS

Getting started

You can find the Documentation for CheerpJ, together with tutorials and examples, on the CheerpJ Documentation page.



Leaning Technologies' Blog - everything WebVM, Cheerp, CheerpJ, CheerpX, compile-to-WebAssembly and WebAssembly virtualization

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store