https://github.com/leaningtech/cheerpj-natives
JS implementations of JNI libraries for CheerpJ
https://github.com/leaningtech/cheerpj-natives
Last synced: about 1 year ago
JSON representation
JS implementations of JNI libraries for CheerpJ
- Host: GitHub
- URL: https://github.com/leaningtech/cheerpj-natives
- Owner: leaningtech
- License: apache-2.0
- Created: 2023-12-20T12:15:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-13T07:59:11.000Z (about 2 years ago)
- Last Synced: 2025-04-07T10:51:26.233Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 37.1 KB
- Stars: 11
- Watchers: 7
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cheerpj-natives
[](https://discord.leaningtech.com)
A collection of alternative implementations of [native libraries](https://labs.leaningtech.com/cheerpj3/guides/Implementing-Java-native-methods-in-JavaScript) to be used when running Java applications with [CheerpJ](https://labs.leaningtech.com/cheerpj).
Currently only a partial implementation of LWJGL is included.
# Usage
1. [Download cheerpj-natives](https://github.com/leaningtech/cheerpj-natives/archive/refs/heads/main.zip) and place the `cheerpj-natives` folder at the root of your web server.
2. Pass the following property to the `cheerpjInit` options: `javaProperties: ["java.library.path=/app/cheerpj-natives/natives"]`
## LWJGL
The LWJGL implementation requires that you provide a canvas for it to render to by setting `window.lwjglCanvasElement`. If you don't do this, you'll see the following error:
> Error: window.lwjglCanvasElement is not set or is not a canvas
1. Add this HTML to the start of the document body:
```html
```
2. In your script, add the following line before the `cheerpjRunMain` or `cheerpjRunJar` call:
```js
window.lwjglCanvasElement = document.getElementById("lwjgl");
```
### Example
Following from the [getting started tutorial](https://labs.leaningtech.com/cheerpj3/getting-started/Java-app):
```html
await cheerpjInit({
javaProperties: ["java.library.path=/app/cheerpj-natives/natives"],
});
cheerpjCreateDisplay(800, 600);
window.lwjglCanvasElement = document.getElementById("lwjgl");
await cheerpjRunJar("/app/CHANGEME.jar");
```