Run a Java library

Use Java classes in JavaScript

Deprecation notice
CheerpJ 2 is deprecated. Consider migrating to CheerpJ 3 .

1. Include CheerpJ on your page

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

2. Initialize CheerpJ and load your Java library

cheerpjInit();
cheerpjRunJar("/app/library.jar");
Don’t forget to use the /app/ prefix
It is common for first-time users to forget to add the prefix β€œ/app/” when passing the application location to cheerpJRunJar() or cheerpjRunMain().

This will load library.jar from the root of your web server.

3. Call Java from JavaScript

let obj = await cjNew("com.library.MyClass");
await cjCall(obj, "myMethod");

Further reading

Was this page helpful?
Suggest changes