-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed AOT and Java DOM content, updated some links, updated app and…
… applet getting started examples, changelog, minor updates on index
- Loading branch information
1 parent
9517d8d
commit e0fb784
Showing
15 changed files
with
1,368 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: FAQ | ||
--- | ||
|
||
## What is CheerpJ? | ||
|
||
CheerpJ is a solution for converting unmodified Java client applications into browser-based HTML5/JavaScript web applications. CheerpJ consists of a full Java runtime environment in JavaScript, and of a on-the-fly compiler for dynamic class generation, to be deployed alongside the application. | ||
|
||
## What does the CheerpJ compiler do? | ||
|
||
The CheerpJ compiler, based on LLVM/Clang, as well as on parts of [Cheerp](https://github.com/leaningtech/cheerp-meta), converts Java bytecode into JavaScript, without requiring the Java source. CheerpJ can be invoked on whole Java archives (.jar) or on single .class files. | ||
|
||
## What parts of the Java SE runtime are supported? | ||
|
||
The CheerpJ runtime environment is a full Java SE runtime in JavaScript. Differently from other technologies which provide a partial re-implementation written manually in JavaScript, we opted to convert the entire OpenJDK Java SE runtime to JavaScript using CheerpJ. The CheerpJ runtime is constituted of both JavaScript files and .jar archives. All CheerpJ runtime components are dynamically downloaded on demand by the application to minimise total download size. The CheerpJ runtime library is hosted by us on a dedicated CDN-backed domain, and we invite users to link to it in order to take advantage of caching and cross-application resource sharing. | ||
|
||
## Can I use CheerpJ to convert my legacy Java application? I have no longer access to the source code. | ||
|
||
Yes, you can convert any Java SE application with CheerpJ without touching the source code. You only need all the .jar archives of your application. | ||
|
||
## Can I use CheerpJ to convert Java libraries and integrate them in my HTML5 application? | ||
|
||
Yes. Java methods can be exposed to JavaScript with an asynchronous interface. A synchronous-looking construct is provided to minimise verbosity when multiple methods are invoked. | ||
|
||
## Can I call JavaScript libraries or web APIs from Java? | ||
|
||
Yes, CheerpJ allows you to interoperate with any JavaScript or browser API. | ||
|
||
## How does CheerpJ support reflection? | ||
|
||
In order to support reflection, CheerpJ, similarly to a JVM, utilizes the metadata available in the original .jar file. A converted application, to be deployed on a web server, comprises both the converted .jar.js JavaScript files and the .jar archives. After having converted a .jar archive, it is possible to remove all the bytecode from them prior to deployment, in order to minimize download time (we provide a simple tool to do so). The combined size of the pruned .jar archive and the output JavaScript, after compression, is comparable to the original .jar. | ||
|
||
Optionally, .jar archives can be split into multiple segments (size to be defined at compile time) before being deployed. The application will only load the required segments at run time, thus further reducing download time. | ||
|
||
## How does CheerpJ support dynamic class generation? | ||
|
||
One component of CheerpJ is the CheerpJ on-the-fly compiler (cheerpJ.js), a minimalistic Java-bytecode-to-JavaScript compiler written in C++ and compiled to JavaScript. CheerpJ.js needs to be distributed alongside any converted Java application that makes use of dynamic constructs such as proxy classes, which get compiled on the fly at run time directly on the browser. | ||
Check failure on line 37 in src/content/docs/cheerpj3/00-faq.md GitHub Actions / vale[vale] src/content/docs/cheerpj3/00-faq.md#L37
Raw output
|
||
|
||
## What is the size of the output of CheerpJ | ||
|
||
The combined size of the .jar to be served (pruned of its bytecode) and of the resulting JavaScript is similar to that of the original .jar archive. Anecdotally, an overhead of 20% seems to be the average. | ||
|
||
## The size of the output is too big! Why doesn't CheerpJ remove "dead code"? | ||
|
||
In Java there is no "dead code". Java supports reflection, so all code and classes can be potentially used at runtime. For this reason CheerpJ cannot automatically remove any code. | ||
|
||
This said, depending on the application, it is often possible to remove a lot of code using ProGuard: an industry standard open source tool. CheerpJ provides support to automatically generate a ProGuard configuration file to make sure that classes used via reflection are not removed. For more information see: [here](/cheerpj3/guides/Startup-time-optimization#use-proguard-to-remove-unused-code) | ||
|
||
## Can JavaScript code produced by Cheerp be plugged into Node.js? | ||
|
||
Yes, it should. However, this has not been one of our areas of focus so far. | ||
|
||
## When compiling my application I see the message `Failure compiling MyFile.class`, but cheerpjfy continues to execute with no errors | ||
|
||
This means that it was not possible to use the new codegen. CheerpJ will use, for this class, the legacy codegen. This might happen for multiple classes in the same .jar, | ||
|
||
## My Java application needs to get data over the network, but I only get `SocketException`s | ||
|
||
In the browser environment it is not possible to use sockets to connect to arbitrary ports. As a special exception CheerpJ provides a custom HTTP/HTTPS handler (based on XHR) that can be used to get data over HTTP and use REST APIs. To enable this handler please set the property `java.protocol.handler.pkgs=com.leaningtech.handlers` during the `cheerpjInit` call, for example: | ||
|
||
`cheerpjInit({javaProperties:["java.protocol.handler.pkgs=com.leaningtech.handlers"]});` | ||
|
||
Please note that when using CheerpJ to run applets the custom handlers are enabled by default. | ||
|
||
## When I run an application compiled with CheerpJ I see 404 errors in the browser console. What's going on? | ||
|
||
Ignore those errors. CheerpJ provides a filesystem implementation on top of HTTP. In this context it is absolutely ok for some files to be missing. CheerpJ will correctly interpret 404 errors as a file not found condition. | ||
|
||
## My application compiled with CheerpJ does not work and I just see the "CheerpJ runtime ready" on the top of the screen. What's going on? | ||
|
||
Many first time users get stuck at this point. The most common issues are: | ||
|
||
- Opening the HTML page directly from disk: The URL in the browser should always start with http:// or https://, if it starts with file:// CheerpJ will not work. You need to use a local web server during testing. | ||
- Forgetting to add "/app/" prefix to the JAR files used in Web page. CheerpJ implements a virtual filesystem with multiple mount points, the "/app/" prefix is required. | ||
- More in general, you can use the "Network tab" of the developer tools in the browser to check if the JAR is being correctly downloaded. If the JAR is never downloaded, or a 404 error is returned, something is wrong with the JAR path. If you don't see anything in the "Network tab", please reload the page while keeping the developer tools open. | ||
- When converting obfuscated JARs on MacOS and Windows there might be collisions between classes due to the case-insensitive nature of the filesystem. For example `a.class` and `A.class` will be considered the same. Always try to convert the JAR using a Linux machine before reporting a bug when converting obfuscated JARs. | ||
|
||
## My application compiled with CheerpJ does not work and I see a cross origin error to a Google service in the console. What's going on? | ||
|
||
The cross origin message you see happens as part of our automatic bug reporting system and it is not the real error. Something else is making your application crash, please report a bug [here](https://github.com/leaningtech/cheerpj-meta/issues). | ||
|
||
## Can I play Old School RuneScape using CheerpJ or the CheerpJ Applet Runner extension? | ||
|
||
Not yet. The main problem is that RuneScape requires low level network connections primitives (sockets) which are not provided by browsers at this time due to security concerns. In the future we might provide a paid add-on to the CheerpJ Applet Runner extension to support this use case via tunneling. | ||
|
||
## How can I use CheerpJ to generate WebAssembly code instead of JavaScript? | ||
|
||
CheerpJ cannot be used to generate WebAssembly code at the moment. | ||
|
||
CheerpJ uses WebAssembly internally for some components of the runtime, but Java bytecode can only be compiled to JavaScript at this time since WebAssembly currently is not an efficient target for Java. CheerpJ will support WebAssembly output when the platform matures. | ||
|
||
## What is the status of CheerpJ? | ||
|
||
CheerpJ is actively developed by [Leaning Technologies Ltd](https://leaningtech.com), a British-Dutch company focused on compile-to-JavaScript and compile-to-WebAssembly solutions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Demos | ||
--- | ||
|
||
To showcase the capabilities of the CheerpJ compiler we have published several demos | ||
|
||
## OpenAstexViewer | ||
|
||
<img src="/cheerpj2/assets/demo_openastex.png" width="400"> | ||
|
||
This demo highlights how complex Java applets with 3D rendering can efficiently and safely run in any browser using CheerpJ. | ||
|
||
This specific applet is a visualization tool for protein structures. | ||
|
||
- Go to the [demo](https://cheerpjdemos.leaningtech.com/OpenAstexViewer.html) | ||
- Find the source code [here](https://github.com/openastexviewer/openastexviewer) | ||
|
||
## Swing examples: | ||
|
||
<img src="/cheerpj2/assets/demo_swing.png" width="400"> | ||
|
||
A few selected Java Swing examples to demonstrate how complex Swing GUI apps can be automatically converted to HTML5/JavaScript. | ||
|
||
- Go to the [demo](https://cheerpjdemos.leaningtech.com/SwingDemo.html) | ||
- [Source](https://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html) | ||
|
||
## JavaFiddle | ||
|
||
<img src="/cheerpj2/assets/demo_fiddle.png" width="400"> | ||
|
||
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](https://javafiddle.leaningtech.com/) (please inspect the page using the devtools). | ||
|
||
## iText Demo | ||
|
||
<img src="/cheerpj2/assets/demo_itext.png" width="400"> | ||
|
||
Edit PDFs fully client side using the industry standard [iText](https://itextpdf.com/en) library converted to JavaScript. This demo demonstrates how CheerpJ APIs can be used to instance Java objects and call methods directly from JavaScript. | ||
|
||
- Go to the [demo](https://cheerpjdemos.leaningtech.com/iTextDemo.html) | ||
- [Source](https://cheerpjdemos.leaningtech.com/itextCheerpJDemo.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Changelog | ||
--- | ||
|
||
version 3.0 - September 22nd, 2023: | ||
|
||
``` | ||
Focus on performance, particularly on startup time | ||
* Multiple fixes on the Cheerp compiler to better optimize JNI code | ||
* Multiple experiments on the JIT to better interact with V8 tiering | ||
``` | ||
|
||
version 3.0 - September 15th, 2023: | ||
|
||
``` | ||
Work on CJ3 Library mode, with a focus on performance and Java <-> JS type conversions | ||
* Optimized away context switching overhead on user native calls | ||
* Support many more type conversion between JS numbers/integers/booleans and Java primitive types | ||
* Support conversion between JS numbers and Java boxed types (i.e. java.lang.Integer) | ||
* JIT optimizations | ||
* Optimization of the core class loading code path | ||
``` | ||
|
||
version 3.0 - September 8th, 2023: | ||
|
||
``` | ||
JNLP support and performance work | ||
* Significant speed up of System.arrayCopy | ||
* JIT optimizations | ||
``` | ||
|
||
version 3.0 - September 1st, 2023: | ||
|
||
``` | ||
Focus on networking | ||
* Integrated Tailscale support for low level TCP/UDP traffic, same code we use for WebVM/CheerpX | ||
* Custom HTTP/HTTPS handlers are now enabled by default unless Tailscale is used. The handlers provide http/https support in common cases. | ||
* Optimized exception handling | ||
* Optimized code rendering | ||
* Multiple JIT optimizations | ||
``` |
85 changes: 85 additions & 0 deletions
85
src/content/docs/cheerpj3/03-getting-started/00-Java-app.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
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/3_20230819_174/cj3loader.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
async function myInit() { | ||
await cheerpjInit(); | ||
await cheerpjCreateDisplay(800, 600); | ||
await cheerpjRunJar("/app/my_application_archive.jar"); | ||
} | ||
myInit(); | ||
</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 | ||
|
||
- [Runtime API](/cheerpj3/reference/Runtime-API) |
101 changes: 101 additions & 0 deletions
101
src/content/docs/cheerpj3/03-getting-started/01-Java-applet.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
title: Run a Java applet | ||
--- | ||
|
||
import LinkButton from "../../../../components/LinkButton.astro"; | ||
Check failure on line 5 in src/content/docs/cheerpj3/03-getting-started/01-Java-applet.mdx GitHub Actions / vale[vale] src/content/docs/cheerpj3/03-getting-started/01-Java-applet.mdx#L5
Raw output
|
||
|
||
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](/cheerpj3/getting-started/Java-applet#running-your-own-applet) using the CheerpJ runtime environment and the `<cheerpj-applet>` tag in your own webpage. | ||
- [Running a public applet](/cheerpj3/getting-started/Java-applet#running-a-public-applet) using the [CheerpJ Applet Runner](https://chrome.google.com/webstore/detail/cheerpj-applet-runner/bbmolahhldcbngedljfadjlognfaaein) Chrome extension for applets integrated with the applet tag `<applet>` on 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" {6, 9-15, 17-22} | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>CheerpJ applet test</title> | ||
<script src="https://cjrtnc.leaningtech.com/3_20230819_174/cj3loader.js"></script> | ||
</head> | ||
<body> | ||
<cheerpj-applet | ||
archive="Example.jar" | ||
code="ExamplePath.ExampleApplet" | ||
height="900" | ||
width="900" | ||
> | ||
</cheerpj-applet> | ||
</body> | ||
<script> | ||
async function myInit() { | ||
await cheerpjInit(); | ||
} | ||
myInit(); | ||
</script> | ||
</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 -p 8080 | ||
``` | ||
|
||
### What's going on? | ||
|
||
- The `cheerpjInit({enablePreciseAppletArchives:true});` initializes CheerpJ runtime environment indicating we are loading an applet. | ||
- 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 | ||
|
||
### 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> | ||
|
||
### 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) | ||
|
||
## The result | ||
|
||
You will see the CheerpJ display on your browser with some loading messages before showing your applet running. Depending on your application and the optimizations applied, this could take just a few seconds. | ||
|
||
## Further reading | ||
|
||
- [Runtime API](/cheerpj3/reference/Runtime-API) |
Oops, something went wrong.