Load a Java Library

Loads a Java library for use in JavaScript. See library mode for more information.

async function cheerpjRunLibrary(classPath: string): Promise<CJ3Library>;


  • classPath (string) - The path to the library’s jar file in the virtual filesystem. Pass an empty string to load the standard library only.


cheerpjRunLibrary returns a Promise which resolves to a CJ3Library object.


Using the standard library

await cheerpjInit();
const lib = await cheerpjRunLibrary("");
const System = await;
await System.out.println("Hello from Java");

Using a custom library

Let’s say we had a library called example.jar compiled from the following class:

package com.example;
public class Example {
public String[] greetings = {"Hello", "Bye"};
public void hello() {
System.out.println("Example says hello!");

With example.jar being available on the web server at /example.jar, we could use it like so:

await cheerpjInit();
const lib = await cheerpjRunLibrary("/app/example.jar");
const Example = await;
const example = await new Example();
await example.hello(); // Example says hello!
Was this page helpful?
Suggest changes