CheerpJ Revitalizes Legacy Java Applications
Written by Nikos Vaggalis   
Thursday, 20 February 2020

CheerpJ is a Java-to-Javascript runtime and compiler that can convert any Java application to HTML5 for in-browser rendering. CheerpJ 2.0, which features WebAssembly support, was released earlier this month.


According to its developers, Leaning Technologies, a company which provides WebAssembly solutions, its use-case scenarios are threefold :

  • 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.

  • 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.

  • Using (converted) Java libraries as part of a native web application.

There is another advantage that I would add to that list of scenarios. As browsers  have disabled the Java plugin, essentially killing the running of Java applications in the form of Applets within the browser's sandbox, Enterprises that run mission-critical Applet applications were left in despair with not many options left; running outdated browsers and unpatched Java versions versions which would increase many times over the risk of becoming hacked or exploited. With CheerpJ, at the same time as avoiding being hacked you can also modernize these applications.
Behind the scenes, a full Java 8 SE runtime library lives inside the browser hiding behind WebAssembly, of course.It doesn't stop there, though.Since WebAssembly cannot currently directly access the DOM there is also a JavaScript/DOM interoperability APIs that allows accessing and manipulating the DOM from Java!


Unlike JWebAssembly, which is a Java bytecode to WebAssembly compiler, CheerpJ does not require the source code of the application; you just compile all your .jar archives using the CheerpJ AOT compiler.

The runtime also supports file system access, audio via WebAudio, printing via the browser printing dialogue and HTML5 WebWorkers.

After converting the Java application to Javascript through the compiler you can host it in HTML by linking to the CheerpJ runtime, loader.js, from its cdn:

<!DOCTYPE html>

<html lang="en">  


<meta charset="utf-8">    

<title>CheerpJ test</title>    

<script src=""></script>  




<script>       cheerpjInit();       cheerpjCreateDisplay(800,600);       cheerpjRunMain("AppClass", "/app/my_application_archive.jar:/app/my_dependency_archive.jar");   </script>


This page will initialize the CheerpJ system, create a graphical environment to contain all Java windows and then execute the main method of AppClass. The second parameter of cheerpjRunMain is a separated list of JARs where application classes can be found (the classpath).That is because the original jar files are required  to be deployed alongside the application to support reflection and dynamic class generation, although just the archive structure and metadata are preserved, nothing else.This simple HTML page can now be served on a http server.

CheerpJ's vesion 2.0 introduces extra WebAssembly runtime modules, which are used when computationally heavy operations are required.

Although CheerpJ has a web page on Github, it is closed source and the repo is used only for hosting instructions to get you started. CheerpJ is free to use for non-commercial purposes, as well as for technical evaluation; any other use will require a license. Still if you think that you fit its target group you can check that it works before going for a license as it is freely available for downloading.

Finally, there is an online playground, where you can write Java code and see it rendered in real time with CheerpJ, as well as the CheerpJ Applet Runner Chrome plugin with which you can run legacy Java Applets on Chrome without having to install Java.


More Information

Leaningtech's CheerpJ 2.0

CheerpJ on GitHub

Related Articles

Python & WebAssembly Plus Science Equals Pyodide


To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.


Google Releases Vertex AI Agent Builder

Google has launched Vertex AI Agent Builder, alongside new open-source language models for the Vertex AI platform. The announcements were made at the Google Cloud Next 2024 event.

Google Gemini API Developer Competition

Google is running a Gemini API Developer Competition with prizes including a 1981 custom electric DeLorean. Entrants will use the Gemini API to tackle real-world challenges, and the organizers su [ ... ]

More News

Last Updated ( Thursday, 20 February 2020 )