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!

 cheerjp

  
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">  

<head>    

<meta charset="utf-8">    

<title>CheerpJ test</title>    

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

</head>  

<body>  

</body>  

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

</html>

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.

cheerpjsq

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.

Banner


Grafana 11 Improves Metrics
11/04/2024

Grafana Labs, creators of the Grafana open-source metrics analytics and visualization suite, has announced the preview release of Grafana 11 with improvements to make it easier to view metrics, and ch [ ... ]



Supersimple - Deep Insights From Data
02/04/2024

Announcing $2.2 Million in pre-seed funding, the Estonian startup Supersimple has launched an AI-native data analytics platform which combines a semantic data modeling layer with the ability to answer [ ... ]


More News

Last Updated ( Thursday, 20 February 2020 )