Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CJ2 docs rearranging #16

Merged
merged 16 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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, 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>
<script>
cheerpjInit();
cheerpjCreateDisplay(800, 600);
cheerpjRunMain(
"ChangeThisToYourClassName",
GabrielaReyna marked this conversation as resolved.
Show resolved Hide resolved
"/app/my_application_archive.jar:/app/my_dependency_archive.jar",
);
</script>
</body>
</html>
```

Alternatively, if your application is designed to be executed with the command `java -jar` you can replace `cheerpjRunMain()` for the following line:

```js
cheerpjRunJar("/app/my_application_archive.jar");
```
GabrielaReyna marked this conversation as resolved.
Show resolved Hide resolved

## 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 local web server. Opening the `.html` page directly from the disk (for example, by double-clicking on it) is **_not supported_**. This is a very common mistake for first time users.
GabrielaReyna marked this conversation as resolved.
Show resolved Hide resolved

## 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()`.

Check failure on line 71 in src/content/docs/cheerpj2/03-getting-started/00-Java-app.md

View workflow job for this annotation

GitHub Actions / vale

[vale] src/content/docs/cheerpj2/03-getting-started/00-Java-app.md#L71

[Vale.Spelling] Did you really mean 'initilized'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'initilized'?", "location": {"path": "src/content/docs/cheerpj2/03-getting-started/00-Java-app.md", "range": {"start": {"line": 71, "column": 34}}}, "severity": "ERROR"}
- `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
Loading