Integrate Java Libraries into your Web Application

CheerpJ Core allows web developers to integrate Java libraries and components in native web applications.

CheerpJ is a browser-side JVM replacement in WebAssembly and supports seamless interoperability with HTML5/JavaScript.

index.html
<script src="https://cjrtnc.leaningtech.com/4.3/loader.js"></script>
<script type="module">
  await cheerpjInit();
  const lib = await cheerpjRunLibrary("");
  const System = await lib.java.lang.System;
  await System.out.println("Hello from Java");
</script>

Run a Java library in four steps

CheerpJ loads an existing Java library in the browser, so you can call its classes and methods from JavaScript without changing the original code. You need the library’s compiled JAR file, not its source code.

To get started, you need:

  • Your library’s .jar file
  • An HTML page to load it from
  • A simple HTTP server to test the page locally
  1. Create a project directory

    Create a folder for the project and copy your JAR file into it. Your HTML file goes in the same folder.

    Terminal
    mkdir my-project
  2. Create an HTML file with CheerpJ

    Add CheerpJ’s loader script to the page, then call cheerpjInit to start the CheerpJ runtime.

    index.html
    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <title>CheerpJ library mode test</title>
        <script src="https://cjrtnc.leaningtech.com/4.3/loader.js"></script>
      </head>
      <body>
        <script type="module">
          await cheerpjInit();
        </script>
      </body>
    </html>
  3. Load the library and call it from JavaScript

    Call cheerpjRunLibrary with the path to your JAR. /app/ is the root of your web server, so this loads library.jar from the project directory. You then use the library’s classes and methods as JavaScript objects. The class and method names here are examples, so replace them with your own.

    index.html
    <script type="module">
      await cheerpjInit();
      const cj = await cheerpjRunLibrary("/app/library.jar");
      const MyClass = await cj.com.library.MyClass;
      const obj = await new MyClass();
      await obj.myMethod();
    </script>
  4. Host your page

    Serve the project directory with any HTTP server, such as http-server.

    Terminal
    npx http-server -p 8080

The result

Open the page and CheerpJ starts in the browser and loads your library. Once it has loaded, you can call the library’s methods directly from JavaScript. Depending on the size of the library and the optimisations applied, this can take a few seconds before your code starts running.

Key Features

01

Full Java environment in HTML5

CheerpJ enables modern browsers to run any Java Application and Applet, as well as Java libraries.

02

Legacy Modernization

With CheerpJ, you can run legacy Java Applets and Applications on modern browsers, removing the requirement for IE, Edge IE mode, and for a local Java installation.

03

Effortless Deployment

CheerpJ does not need access to the source code at all, operating at the level of Java bytecode. Third-party libraries, dependencies and obfuscated code pose no issue.

04

JVM replacement

CheerpJ core component is a Java Bytecode JIT compiler in WebAssembly.

05

Full Runtime

CheerpJ comes with a full OpenJDK runtime environment, ensuring that existing applications ‘will just work’. This includes Java Swing, AWT, and any other runtime component.

06

Full Classloader Support

CheerpJ can now give full control to the appropriate Classloader for class resolution, including application-provided ones. This completely eliminates incompatibilities caused by duplicated classes as well.

07

Scalable JNI Architecture

CheerpJ compiles 100% of the OpenJDK native code to WebAssembly, providing a viable path for supporting modern versions of Java and potentially specific point versions if a user requires.

08

Java-JavaScript Interoperability

CheerpJ provides multiple mechanisms for Java and JavaScript to interoperate.

09

Networking and System Features

CheerpJ provides a full networking stack (HTTP(s), TCP/IP), as well as support for file access, networking (HTTP and TCP), clipboard, audio, printing, and more.

Here Are the Most Frequent Questions

More FAQs
What types of applications does CheerpJ support?

CheerpJ can run Java Applets, Java Web Start applications, stand-alone Java applications (including Swing), and Java libraries, on any modern browser that supports WebAssembly.

What is the main difference between CheerpJ and any other Java migration tool on the market?

CheerpJ is the only full Java Runtime Environment for the browser, extensively compatible with Java SE and equipped with a full build of the OpenJDK JRE. By using CheerpJ, you will not need to modify your application – it will just work on any browser, without a local Java installation.

Why should I use CheerpJ?

You can use CheerpJ in two scenarios:

  1. To preserve and improve access to existing legacy Java applications, including third-party ones, in the form of Java Applets, Java Web Start, or standalone. With CheerpJ, you can extend the life of mission-critical Java content, improve its security, and eliminate the need for legacy browsers and Java Desktop installations.
  2. If you are a developer, to modernise existing Java applications into web applications, without rewriting them. CheerpJ allows you to use existing Java either to develop a full application, or to preserve parts of the application (e.g. the client-side business logic) with a new HTML5 UI, breathing new life in your application with minimal investment.
Can I use CheerpJ to run Oracle Forms, Oracle EBS, or any other Java-based Oracle product?

Yes. CheerpJ is used by many organizations worldwide to run Oracle Java-based products, such as Oracle Forms and Oracle E-Business Suite, on modern browsers. This includes several Fortune 500 companies as well as local and federal government agencies.

Is CheerpJ secure?

CheerpJ is a full JVM in WebAssembly, running client-side within the browser sandbox. It has no native or server-side components. As such, it benefits from the Web security model, drastically improving the application security profile compared to standard Java applications.

Learn More About CheerpJ

Build with Java for the browser.