CheerpJ 1.2 released

ProGuard integration, system clipboard support, new optimisations

Stefano De Rossi
leaningtech
4 min readSep 6, 2018

--

Today we are excited to release CheerpJ 1.2, the latest major update to our Java to JavaScript compiler.

CheerpJ 1.2 can be downloaded here, with the main Documentation available here.

This release introduces two features which have been highly requested by our commercial users: an integration with ProGuard to allow major reductions in startup time and download size, and full integration with the system clipboard, allowing to copy and paste between the browser and the system. This release introduces further optimisations to memory use, size of generated code and networking.

It is easy to try CheerpJ 1.2! Download the new version of the compiler here, and follow our tutorials to get started. If you have been using a previous version of CheerpJ, make sure to rebuild your project, and change your CheerpJ runtime loader to:

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

ProGuard integration for startup and size optimisations

ProGuard is an industry standard, open-source tool to optimise and obfuscate Java bytecode. CheerpJ 1.2 introduces a convenient way to integrate ProGuard in your Java-to-JavaScript toolchain in order to optimise and reduce the download size of your application.

ProGuard can automatically trace the classes used by an application, and generate a minimised version of a Java archive in which unused classes, methods and fields are automatically purged. This usually leads to a very significant reduction in the size of the package, and to a startup performance speedup, especially when multiple third-party libraries are used.

Since CheerpJ fully supports runtime reflection, ProGuard may end up removing used code, causing unexpected errors at runtime.

To provide a more accurate trace of classes that are used by an application, including those invoked via reflection, CheerpJ 1.2 introduces a special initialisation option:

cheerpjInit({enableProguardTrace:true})

A CheerpJ application can be initialised with this option, and tested extensively in order to generate a comprehensive list of classes. After this phase, the new

cjGetProguardConfiguration()

method can be used to generate a configuration file (cheerpj.pro) that can be used with ProGuard.

For more details, including a step-by-step guide on how to optimise a CheerpJ application with ProGuard, you can check our Documentation.

Integration with system clipboard

By default, CheerpJ provides an internal clipboard (local to the converted Java application) that can be accessed with the usual Ctrl+C / Ctrl+V (or Cmd+C / Cmd+V) shortcuts. This clipboard is not normally integrated with the system, and therefore copy-pasting from/to other applications or browser tabs is not allowed.

CheerpJ 1.2 introduces a new system integration, to be enabled optionally, which allows a CheerpJ application to interface directly with the system clipboard.

To enable this integration, a special initialisation option is required:

cheerpjInit({clipboardMode:”system”});

Browsers enforce serious limitations on how the system clipboard can be accessed. In practice it is generally accessible when the Ctrl+C and Ctrl+V shortcuts are used (Cmd+C and Cmd+V on macOS).

Due to these limitations, CheerpJ provides the following UX to access the system clipboard:

  • Ctrl+C (Cmd+C on macOS): the user has to enter the shortcut twice to give CheerpJ access to the system clipboard and perform the copy (after keying in Ctrl+C the first time, CheerpJ will block the execution while waiting for the second Ctrl+C).
  • Ctrl+V (Cmd+V on macOS): this shortcut behaves normally, with no difference with native execution.
  • Menu based Copy/Paste: Ctrl+C/Ctrl+V are needed to access the clipboard. CheerpJ will block the execution while waiting the appropriate shortcut.

In future version of CheerpJ, we will add an additional clipboard mode to take advantage of a the new permission-based browser API for clipboard access which is currently being standardized. This future mode will provide native like user experience in all cases.

Other features

In addition to ProGuard integration and system clipboard integration, CheerpJ 1.2 introduces further optimisations and several bugfixes:

  • Extended support for window resizing
  • Added support for sealed packages
  • Further optimisations of JNI calls
  • Improved cleanup of threads
  • Improved support for reflection
  • Improved HTTP(s) Java networking support (based on XHR)

Download

Cheerp 1.2 is available to download for Linux, Windows and macOS. To get started with CheerpJ, please visit the main documentation page.

Get in touch

For more information on CheerpJ, check out our website at https://leaningtech.com/cheerpj/. Follow us on twitter (@leaningtech), visit our website, or drop us a line on Gitter!

--

--