Skip to content

Commit

Permalink
edited getting started and added AOT as a guide
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielaReyna committed Sep 20, 2023
1 parent 3022c9e commit 771baa1
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: CheerpJ Applet Runner
subtitle: Run Java applets without installing Java
---

import LinkButton from "../../../../components/LinkButton.astro";
import LinkButton from "../../../components/LinkButton.astro";

The CheerpJ Applet Runner is a browser extension that enables Java applets without requiring a local Java installation or to install deprecated plugins.

Expand Down
58 changes: 58 additions & 0 deletions src/content/docs/cheerpj2/03-getting-started/00-Java-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: Run a Java Application
---

CheerpJ can run a Java application in the browser with little to no modifications. This page will help you getting started with CheerpJ and running your first Java application in the browser.

**To get started you will need:**

- Your java application file(s)
- An HTML file where your Java app will be wrapped
- A simple HTTP server to test your webpage locally

## 1. Create a basic HTML file

Let's start by creating a simplet HTML file like the following example. Please notice the CheerpJ runtime environment has been integrated. In this example we are assuming your HTML file and your .jar files are under the same directory.

```html title="index.html" {6, 9-16}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CheerpJ test</title>
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
</head>
<body></body>
<script>
cheerpjInit();
cheerpjCreateDisplay(800, 600);
cheerpjRunMain(
"ChangeThisToYourClassName",
"/app/my_application_archive.jar:/app/my_dependency_archive.jar",
);
</script>
</html>
```

## 2. Host your page

You can now serve this web page on a simple HTTP server, such as the http-server utility.

```shell
npm install http-server
http-server [path] [options]
```

## What's going on?

- CheerpJ loader is included from our cloud runtime as
`<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>`.
- CheerpJ runtime environment is initilized by `cheerpjInit()`.
- `cheerpjCreateDisplay()` creates a graphical environment to contain all Java windows
- `cheerpjRunMain()` executes the `main` method of `ChangeThisToYourClassName`. The second parameter is a `:` separated list of `.jar` files where application classes can be found (the classpath).
- The `/app/` is a virtual file system mount point that reference the root of the web server this page is loaded from.

## Further reading

- [AOT optimization](/cheerpj2/guides/AOT-optimization)
- [Runtime API](http://localhost:3000/cheerpj2/reference/Runtime-API)
123 changes: 0 additions & 123 deletions src/content/docs/cheerpj2/03-getting-started/01-Getting-Started.md

This file was deleted.

92 changes: 92 additions & 0 deletions src/content/docs/cheerpj2/03-getting-started/01-Java-applet.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: Run a Java Applet
---

import LinkButton from "../../../../components/LinkButton.astro";

CheerpJ can run Java applets in the browser seamlessly. This page will help you getting started with CheerpJ for Java applets.

**There are two different ways to run a Java Applet in the browser:**

- Running your own Java applet using the CheerpJ runtime environment and the `<cheerpj-applet>` tag in your own webpage.
- Running a public applet using the [CheerpJ Applet Runner](https://chrome.google.com/webstore/detail/cheerpj-applet-runner-bet/) Chrome extension for applets integrated with the applet tag `<applet>` in public websites.

## Running your own applet

**You will need:**

- Your applet file(s)
- An HTML file to wrap your applet
- A basic HTTP server to test locally

### 1. Create a basic HTML file

```html title="index.html" {7-10, 13-21}
<!doctype html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>CheerpJ applet test</title>
<script src=" https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
<script>
cheerpjInit({ enablePreciseAppletArchives: true });
</script>
</head>
<body>
<cheerpj-applet
archive="Example.jar"
code="ExamplePath.ExampleApplet"
height="900"
width="900"
>
<p>not able to load Java applet</p>
</cheerpj-applet>
</body>
</html>
```

### 2. Host your page locally

You can now serve this web page on a simple HTTP server, such as the http-server utility.

```shell
npm install http-server
http-server [path] [options]
```

### What's going on?

- The `cheerpjInit({enablePreciseAppletArchives:true});` initializes CheerpJ runtime environment indicating we are running an applet and not an standalone app.
- The `<cheerpj-applet>` tag specifies the code base in a similar manner as the now deprecated `<applet>` tag.

> To avoid potential conflicts with native Java we recommend replacing the original HTML tag with `cheerpj-` prefixed version. You should use `<cheerpj-applet>`, `<cheerpj-object>` or `<cheerpj-embed>` depending on the original tag.
## Running a public applet

### Step 1: Install the CheerpJ applet runner

CheerpJ Applet Runner is available for Chrome and Edge.

<div class="flex flex-wrap gap-3">
<LinkButton
type="primary"
href="https://chrome.google.com/webstore/detail/cheerpj-applet-runner/bbmolahhldcbngedljfadjlognfaaein"
label="Add to Chrome"
iconLeft="openmoji:chrome"
/>

<LinkButton
type="primary"
href="https://microsoftedge.microsoft.com/addons/detail/cheerpj-applet-runner/ebfcpaoldmijengghefpohddmfpndmic"
label="Add to Microsoft Edge"
iconLeft="openmoji:edge"
/>

</div>

### Step 2: Go to a website with an applet

Visit a page with a Java applet, [such as this one](http://www.neilwallis.com/projects/java/water/index.php) and click on the CheerpJ Applet Runner icon in the toolbar and enable CheerpJ.

![](/cheerpj2/assets/cheerpj_applet_demo.gif)
Loading

0 comments on commit 771baa1

Please sign in to comment.