Skip to content

Commit

Permalink
CJ2 docs rearranging (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Bates <[email protected]>
  • Loading branch information
GabrielaReyna and bates64 authored Sep 28, 2023
1 parent 789dbba commit 47ea3eb
Show file tree
Hide file tree
Showing 24 changed files with 772 additions and 501 deletions.
11 changes: 11 additions & 0 deletions .github/styles/Vocab/LeaningTechnologies/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ virtualized
methodName
resolvedMethod
preloadResources
arg
className
resolvedFunc
funcName
JSString
jsCall
runMain
classPath
resolveCall
nops




2 changes: 1 addition & 1 deletion src/components/TableOfContents.astro
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function buildToc(headings: BasicHeading[]) {
toc.push(heading);
} else if (
parentHeadings.get(heading.depth - 1) != undefined &&
heading.depth < 4
heading.depth < 5
) {
parentHeadings.get(heading.depth - 1).subheadings.push(heading);
}
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/cheerp/00-installation/01-ppa.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sudo apt-get update

## Install packages

To install all cheerp components, run
To install all Cheerp components, run

```sh
apt-get install cheerp-core
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/cheerpj2/01-demos.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A few selected Java Swing examples to demonstrate how complex Swing GUI apps can

A playground to compile and run Java programs directly in the browser. Both console and GUI applications are supported. The standard `javac` compiler is used, since `javac` is also written in Java the whole compiler runs in the browser, together with the compiled application.

- Go to the [demo](ttps://javafiddle.leaningtech.com/) (please inspect the page using the devtools).
- Go to the [demo](https://javafiddle.leaningtech.com/) (please inspect the page using the devtools).

## iText Demo

Expand Down
83 changes: 83 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,83 @@
---
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.

Java source code is not needed to use CheerpJ. If you are building your own application you should already have its `.jar` file(s).

**To get started you will need:**

- Your Java application file(s). You can also use this [TextDemo.jar](https://docs.oracle.com/javase/tutorialJWS/samples/uiswing/TextDemoProject/TextDemo.jar) sample.
- An HTML file where your Java app will be wrapped
- A simple HTTP server to test your webpage locally

## 1. Create a project directory

Let's start by creating a project folder where all your files will be. Please copy your java and future HTML files here.

```shell

mkdir directory_name

```

## 2. Create a basic HTML file

Let's create a basic HTML file like the following example. Please notice the CheerpJ runtime environment has been integrated and initialized. In this example we are assuming your HTML file and your `.jar` files are under the project directory you just created.

```html title="index.html" {6, 10-12}
<!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>
<script>
cheerpjInit();
cheerpjCreateDisplay(800, 600);
cheerpjRunJar("/app/my_application_archive.jar");
</script>
</body>
</html>
```

Alternatively, if your application is not designed to be executed with the command `java -jar` you can replace `cheerpjRunJar()` for `cheerpjRunMain()` and pass your qualified class name as an argument. For example:

```js
cheerpjRunMain(
"com.application.MyClassName",
"/app/my_application_archive.jar:/app/my_dependency_archive.jar",
);
```

## 3. 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 -p 8080
```

> To test CheerpJ you must use a web server. Opening the `.html` page directly from the disk (for example, by double-clicking on it) is not supported.
## 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 initialized 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.

## The result

You will see the CheerpJ display on your browser with some loading messages before showing your application running. Depending on your application and the optimizations applied, this could take just a few seconds.

## Further reading

- [AOT optimization](/cheerpj2/guides/AOT-optimization)
- [Runtime API](/cheerpj2/reference/Runtime-API)
92 changes: 0 additions & 92 deletions src/content/docs/cheerpj2/03-getting-started/00-Tutorial.md

This file was deleted.

123 changes: 0 additions & 123 deletions src/content/docs/cheerpj2/03-getting-started/01-Getting-Started.md

This file was deleted.

Loading

0 comments on commit 47ea3eb

Please sign in to comment.