You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md
+65-15Lines changed: 65 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,32 +3,82 @@ title: Run a Java library
3
3
description: Use Java classes in JavaScript
4
4
---
5
5
6
-
## 1. Include CheerpJ on your page
6
+
CheerpJ can load and run Java libraries directly in the browser, allowing you to call Java classes and methods from JavaScript with no modifications to your original code. This page will help you get started with CheerpJ and show you how to use an existing Java library (`.jar` file) within a web application.
> It is common for first-time users to forget to add the prefix “/app/” when passing the JAR location to cheerpJRunLibrary().
44
+
## 3. Load and Call the Java Library From Java
21
45
22
-
This will load `library.jar`from the root of your web server.
46
+
Now we can load your Java library by calling `cheerpjRunLibrary` which will load the library from the root of your web server. We are assuming your HTML file and your `.jar` files are under the project directory you just created.
You can now serve this web page on a simple HTTP server, such as the http-server utility.
25
72
26
-
```js
27
-
constMyClass=awaitcj.com.library.MyClass;
28
-
constobj=awaitnewMyClass();
29
-
awaitobj.myMethod();
73
+
```shell
74
+
npx http-server -p 8080
30
75
```
31
76
77
+
## The Result
78
+
79
+
You will see CheerpJ initialize in your browser and load the Java library. Once loaded, the methods from your library can be called directly from JavaScript, just as in the example above. Depending on the size of your library and the optimizations applied, this may take just a few seconds before your code begins executing.
80
+
32
81
## Further reading
33
82
83
+
-[Learn more about Library Mode](/docs/guides/library-mode)
0 commit comments