Monday, 19 June, 2017 UTC


Summary



Announcing CheerpJ, a Java compiler for Web applications
We are pleased to announce that we will be releasing our second product CheerpJ, a Java compiler for Web applications.

CheerpJ compiles Java bytecode into JavaScript, and is compatible with 100% of Java, including reflection and dynamic class loading. As such, it is the only solution that allows existing, unmodified Java applications to be executed on any web browser, with no need for plugins or Java installations.

Enabling Java on browsers

In 2013 we released Cheerp, a C++-to-JavaScript compiler which generates fully garbage-collectible, highly optimised JavaScript output. Thanks to tools like Cheerp and Emscripten by Mozilla, compiling C/C++ to a browser target is now commonplace, particularly in the gaming industry. The same cannot be said for Java.

Over the last year, and with the help of several early adopters, we have been working on the development of a solution to run full Java applications and libraries as Web applications. Contrary to Cheerp, the main aim of CheerpJ is to allow existing, unmodified Java applications and libraries to be converted into Web applications with minimal effort from the developer.

Current solutions to enable Java on browsers such as GWT or TeaVM provide incomplete support for Java constructs (e.g. no reflection) and a partial implementation of the Java runtime library. As a result, they are best suited for the development of new applications, rather than for the conversion of existing ones.

The main purpose of CheerpJ is to allow developers to convert legacy Java code into browser-based Web applications, thereby not requiring any Java installation on the client side. By allowing to convert any Java code into JavaScript, CheerpJ also allows server-side Java components to be converted to client-side browser-based libraries, or native Java code to be converted into platform-independent components for node.js.

What is CheerpJ?

CheerpJ is a solution for enabling the development of client-side Web applications in Java. It consists of an offline compiler from Java bytecode to JavaScript, of a Java runtime environment in JavaScript, and of a on-the-fly compiler for dynamic class generation, to be deployed alongside the application.

CheerpJ compiler

The CheerpJ compiler is the core component of CheerpJ. Based on LLVM/Clang, as well as on parts of Cheerp, our C++ compiler, CheerpJ converts Java bytecode into JavaScript, without requiring the Java source.

CheerpJ can be invoked on whole Java archives (.jar) or on single .class files, and generates a .jar.js (or .js) output. In order to support reflection, CheerpJ utilizes the metadata available in the original .jar file. A converted application, to be deployed on a web server, comprises both the converted .jar.js JavaScript files and the .jar archives.

After having converted a .jar archive, it is possible to remove all the bytecode from them prior to deployment, in order to minimize download time (we provide a simple tool to do so). The combined size of the pruned .jar archive and the output JavaScript, after compression, is at most comparable to the original .jar, and very often significantly less.

Optionally, .jar archives can be split into multiple segments (size to be defined at compile time) before being deployed. The application will only load the required segments at run time, thus further reducing download time.

CheerpJ can convert any valid Java archive, and use any Java SE runtime function, with no need for manual intervention from the developer. Currently, CheerpJ supports a JavaScript target and produces fully garbage-collectible code, but WebAssembly will be added at a later stage.

CheerpJ provides fully-transparent bidirectional interoperability between Java and JavaScript. As a result, it is possible to invoke any JavaScript library or browser API from Java. Similarly, any Java method can be exposed to JavaScript.

CheerpJ also provides a choice of filesystem access methods. This includes a read-only filesystem based on HTTP, a local read-write filesystem based on indexDB which is persistent across sessions, and a facility  to access JS strings as files, useful to pass input data to target converted Java programs.

CheerpJ runtime environment

The CheerpJ runtime environment is a full Java SE runtime in JavaScript. Differently from other technologies which provide a partial re-implementation written manually in JavaScript, we opted to convert the entire OpenJDK Java SE runtime to JavaScript using CheerpJ
  
The CheerpJ runtime is constituted of both JavaScript files and .jar archives. All CheerpJ runtime components are dynamically downloaded on demand by the application to minimise total download size.

The CheerpJ runtime library is hosted by us on a dedicated CDN-backed domain, and we invite users to link to it in order to take advantage of caching and cross-application resource sharing.

CheerpJ on-the-fly compiler (CheerpJ.js)

The third component of CheerpJ is the CheerpJ on-the-fly compiler, a minimalistic Java-bytecode-to-JavaScript compiler written in C++ and compiled to JavaScript. CheerpJ.js needs to be distributed alongside any converted Java application that makes use of dynamic constructs such as proxy classes, which get compiled on the fly at run time directly on the browser.

Demos

To illustrate the capabilities and current status of development of CheerpJ, we are releasing some demos, available at this address. In addition, we are releasing a free to use* Chrome extension that enables Java applets through on-the-fly compilation by CheerpJ.js.

Demo 1 and 2 - Conversion of full Java applications to Web applications

A first set of demos shows four example browser-based Swing/AWT applications, converted in full from Java archives (original .jar files available here).

A second set of three demos, available here, belong to a collection of educational applications developed by our friends at PhET. These applications are developed entirely in Java, and use extensive third-party components including MongoDB, JFreeChart and Piccolo2D, which get also converted automatically by CheerpJ.

Demo 3 - Conversion of Java libraries to client-side JavaScript libraries

This demo, developed with the help of our friends at iText, provides an example of a Java library converted to JavaScript, and integrated in a HTML5/JavaScript application. The page interacts with the converted Java through simple methods provided by CheerpJ to allow to invoke any class and instance method, in a mixed synchronous-asynchronous fashion.

Bonus - CheerpJ Applet Enabler Chrome Extension (Beta)


As a bonus, we are releasing to the public a free to use Chrome extension that enables Java applets without the need of plugins and a local Java installation. The extension can be downloaded here.

Since Java Applets have lost support on the majority of browsers, a tremendous amount of content, particularly in science and education, is virtually inaccessible. We aim at providing a solution to extend the life of Java applets on modern browsers.

The CheerpJ Applet Enabler Extension works by converting the Java Applet on the fly through CheerpJ.js, a minimal Java-bytecode-to-JavaScript compiler, and linking it to the CheerpJ runtime environment.

Similarly to the other demos, the very first execution of the Extension will lead to an initial download of approximately 16Mb. Subsequent uses will only need to download the applet content.

You can try the extension on any applet you like (e.g.  https://goo.gl/u9PKA7, https://goo.gl/YVUdMk, https://goo.gl/x3sC7d, https://goo.gl/tZfPXU).

The CheerpJ Applet Enabler Extension is in beta, and we welcome any feedback and bug report on it either through the Extension or on GitHub. Currently, multiple-window applets and pages with multiple applets are not supported. Some AWT elements might also not render properly.

We aim at supporting as many Java applets as possible, and eventually Java WebStart applications.

When will CheerpJ be available?

With CheerpJ in the final phases of development, we are currently working with a selected number of early adopters interested in evaluating the technology before its availability on the market. If you or your organization are interested in working with us ahead of the public release of CheerpJ, please feel free to write us at info@leaningtech.com.

In late July, we will make a restricted public release of CheerpJ and start collecting feedback from the general public.

We expect to release CheerpJ at the end of the summer. Details on the commercial licensing model will be made available at a later date.

About

More information is available at our official site http://leaningtech.com/cheerpj. Feel free to ask any question by email at info@leaningtech.com.

Leaning Technologies is the company behind Cheerp. We provide compile-to-JavaScript tools and professional services for the development of high-performance, large-scale Web applications. Beside our compilers, we provide consulting services to help your business bringing your application to the Web. For more information, drop us a line at info@leaningtech.com.

Follow us on twitter (@leaningtech) and visit http://leaningtech.com/cheerpj to receive all our updates.