From 33b49eb550c88f40a4489f829603c1a77ad8082b Mon Sep 17 00:00:00 2001 From: Rijul Shrestha Date: Thu, 23 Oct 2025 12:48:56 +0100 Subject: [PATCH 1/7] Added introduction and reference to library-mode docs --- .../src/content/docs/10-getting-started/02-Java-library.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md index f0d3ac0b..e97c0301 100644 --- a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md +++ b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md @@ -3,6 +3,10 @@ title: Run a Java library description: Use Java classes in JavaScript --- +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. + +Java source code is not required to use CheerpJ. If you are using your own library, you should already have its compiled `.jar` file available. + ## 1. Include CheerpJ on your page ```html @@ -31,4 +35,5 @@ await obj.myMethod(); ## Further reading +- [Learn more about Library Mode](/docs/guides/library-mode) - [`cheerpjRunLibrary` reference](/docs/reference/cheerpjRunLibrary) From 9880242298880412fe8940930add8dff39ce8447 Mon Sep 17 00:00:00 2001 From: Rijul Shrestha Date: Thu, 23 Oct 2025 15:36:53 +0100 Subject: [PATCH 2/7] Added more context and aligned the formatting with other pages --- .../src/content/docs/10-getting-started/01-Java-applet.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx b/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx index 71f77e5e..9deefee3 100644 --- a/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx +++ b/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx @@ -25,9 +25,9 @@ CheerpJ can run Java applets in the browser seamlessly. This page will help you **You will need:** -- Your applet file(s) +- Your applet file(s). - The HTML file where your applet is meant to be displayed. -- A basic HTTP server to test locally +- A simple HTTP server to test your webpage locally. ### 1. Integrating CheerpJ in your HTML file From 39623902f4aa7a0e928fd0cb333a2bee24fd6d94 Mon Sep 17 00:00:00 2001 From: Rijul Shrestha Date: Thu, 23 Oct 2025 16:01:02 +0100 Subject: [PATCH 3/7] Revert "Added more context and aligned the formatting with other pages" This reverts commit 9880242298880412fe8940930add8dff39ce8447. --- .../src/content/docs/10-getting-started/01-Java-applet.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx b/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx index 9deefee3..71f77e5e 100644 --- a/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx +++ b/sites/cheerpj/src/content/docs/10-getting-started/01-Java-applet.mdx @@ -25,9 +25,9 @@ CheerpJ can run Java applets in the browser seamlessly. This page will help you **You will need:** -- Your applet file(s). +- Your applet file(s) - The HTML file where your applet is meant to be displayed. -- A simple HTTP server to test your webpage locally. +- A basic HTTP server to test locally ### 1. Integrating CheerpJ in your HTML file From 43925fc47ebac6b3dd39fb5ee42df92d130e5ba7 Mon Sep 17 00:00:00 2001 From: Rijul Shrestha Date: Thu, 23 Oct 2025 16:04:35 +0100 Subject: [PATCH 4/7] Added more context and aligned the formatting with other pages --- .../10-getting-started/02-Java-library.md | 73 +++++++++++++++---- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md index e97c0301..b105e007 100644 --- a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md +++ b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md @@ -7,32 +7,75 @@ CheerpJ can load and run Java libraries directly in the browser, allowing you to Java source code is not required to use CheerpJ. If you are using your own library, you should already have its compiled `.jar` file available. -## 1. Include CheerpJ on your page +**To get started you will need:** +- Your `.jar` file. +- An HTML file where your Java app will be wrapped. +- A simple HTTP server to test your webpage locally. -```html - +## 1. Create a Project Directory + +Let's start by creating a project folder where all your files will be. Copy your java and future HTML files here. + +```shell +mkdir directory_name ``` -## 2. Initialize CheerpJ and load your Java library +## 2. Create a Basic HTML File -```js -await cheerpjInit(); -const cj = await cheerpjRunLibrary("/app/library.jar"); +Let's create a basic HTML file and include and initialize CheerpJ on your page. cheerpjInit initialises the CheerpJ runtime environment. + +```html title="index.html" {6, 10} + + + + + CheerpJ Library Mode Test + + + + + + ``` -> [!help] 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 JAR location to cheerpJRunLibrary(). +## 3. Load and Call the Java Library From Java + +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. -This will load `library.jar` from the root of your web server. +```html title="index.html" {11-14} + + + + + CheerpJ Library Mode Test + + + + + + +``` + +## 3. Host your page -## 3. Call Java from JavaScript +You can now serve this web page on a simple HTTP server, such as the http-server utility. -```js -const MyClass = await cj.com.library.MyClass; -const obj = await new MyClass(); -await obj.myMethod(); +```shell +npx http-server -p 8080 ``` +## The Result + +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. + ## Further reading - [Learn more about Library Mode](/docs/guides/library-mode) From 03996a472ce1a58ef7d62baa43e2e1b8e43624a1 Mon Sep 17 00:00:00 2001 From: Rijul Shrestha Date: Thu, 23 Oct 2025 16:17:00 +0100 Subject: [PATCH 5/7] Fixed Lint / Prettier formatting error --- .../content/docs/10-getting-started/02-Java-library.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md index b105e007..e1b51fc8 100644 --- a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md +++ b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md @@ -8,6 +8,7 @@ CheerpJ can load and run Java libraries directly in the browser, allowing you to Java source code is not required to use CheerpJ. If you are using your own library, you should already have its compiled `.jar` file available. **To get started you will need:** + - Your `.jar` file. - An HTML file where your Java app will be wrapped. - A simple HTTP server to test your webpage locally. @@ -55,10 +56,10 @@ Now we can load your Java library by calling cheerpjRunLibrary which will load t From d0b8f7a904b91e2533bc206f98319217e3a6303e Mon Sep 17 00:00:00 2001 From: Rijul Shrestha Date: Sat, 25 Oct 2025 18:48:11 +0100 Subject: [PATCH 6/7] Addressed review feedback; styling consistency and clarify examples --- .../src/content/docs/10-getting-started/02-Java-library.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md index e1b51fc8..34cf3432 100644 --- a/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md +++ b/sites/cheerpj/src/content/docs/10-getting-started/02-Java-library.md @@ -23,7 +23,7 @@ mkdir directory_name ## 2. Create a Basic HTML File -Let's create a basic HTML file and include and initialize CheerpJ on your page. cheerpjInit initialises the CheerpJ runtime environment. +Let's create a basic HTML file and include and initialize CheerpJ on your page. The `cheerpjInit` command initialises the CheerpJ runtime environment. ```html title="index.html" {6, 10} @@ -43,9 +43,9 @@ Let's create a basic HTML file and include and initialize CheerpJ on your page. ## 3. Load and Call the Java Library From Java -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. +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. -```html title="index.html" {11-14} +```html title="index.html" {12-15} @@ -56,6 +56,7 @@ Now we can load your Java library by calling cheerpjRunLibrary which will load t