1
0
mirror of https://github.com/leaningtech/cheerpj-meta.git synced 2025-03-15 01:54:48 +01:00

remove old docs

This commit is contained in:
Alex Bates 2023-10-04 14:47:15 +01:00
parent 026d819c6f
commit 514e1a8ac9
33 changed files with 68 additions and 1440 deletions

View File

@ -1,27 +0,0 @@
name: rebuildMain
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
sendRequest:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Runs a single command using the runners shell
- name: Send signal
run: |
curl -XPOST -u "${{ secrets.BOT_PAT_USERNAME}}:${{secrets.BOT_PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/leaningtech/leaningtech.github.io/dispatches --data '{"event_type": "rebuild-documentation"}'

View File

@ -1,60 +1,24 @@
---
title: CheerpJ - Convert Java to WebAssembly and JavaScript
---
<h1><img src="assets/logotype.svg" alt="CheerpJ" height="96"></h1>
[![Gitter chat](https://badges.gitter.im/leaningtech/cheerpj.svg)](https://gitter.im/leaningtech/cheerpj)
[![Discord server](https://img.shields.io/discord/988743885121548329?color=%237289DA&logo=discord&logoColor=ffffff)](https://discord.leaningtech.com)
[![GitHub Issues](https://img.shields.io/github/issues/leaningtech/cheerpj-meta.svg)](https://github.com/leaningtech/cheerpj-meta/issues)
[![Live Demos](https://img.shields.io/badge/demo-online-green.svg)](https://leaningtech.com/demo/?cheerpjfilter)
[![npm](https://img.shields.io/npm/v/cheerpj)](https://npm.im/cheerpj)
CheerpJ is a Java bytecode to WebAssembly and JavaScript compiler, compatible with 100% of Java, which allows to compile any Java SE application, library or Java applet into a WebAssembly/JavaScript application.
CheerpJ is a **drop-in replacement** for the JVM, and is compatible with 100% of Java 8, including Swing, reflection and dynamic class loading.
**Main project link**: <https://leaningtech.com/cheerpj/>
[Documentation](https://labs.leaningtech.com/cheerpj)
[Issues](https://github.com/leaningtech/cheerpj-meta/issues)
[Discord server](https://discord.leaningtech.com)
**Download latest version**: [![Latest version](https://img.shields.io/badge/cheerpj-2.3-green.svg)](https://leaningtech.com/download-cheerpj/) [![Latest version changelog](https://img.shields.io/badge/2.3-changelog-green.svg)](Changelog)
![](assets/cheerpj_visual_2.png)
**Link to latest runtime**: ``https://cjrtnc.leaningtech.com/2.3/loader.js``
With CheerpJ, you can:
If you are unsure how to start, try our [Tutorial](https://docs.leaningtech.com/cheerpj/Tutorial).
- Run existing **Java applications** in the browser with no changes
- Include **Java applets** in webpages without legacy plugins
- Migrate **Java Web Start / JNLP** applications to work on modern systems
- Use Java libraries in JavaScript/TypeScript seamlessly
What is CheerpJ?
------
## Licensing
<p align="center"><img src="assets/cheerpj_visual_2.png" width="450"></p>
CheerpJ is constituted of three components:
1. The CheerpJ AOT compiler, an LLVM-based Java-bytecode to JavaScript compiler. This can be used to convert Java archives (e.g. .jar) or single .class files to JavaScript. The CheerpJ AOT compiler is available for Linux, macOS and Windows.
2. The CheerpJ runtime library, a full Java SE runtime in WebAssembly and JavaScript, that can be distributed in part or in full with applications converted with CheerpJ.
3. The CheerpJ on-the-fly Java-to-JavaScript compiler, a reduced JavaScript version of the CheerpJ compiler that can be distributed with applications converted with CheerpJ to enable dynamic features of Java such as reflection.
What is unique about CheerpJ?
-------
1. CheerpJ can convert 100% of Java including reflection and proxy class creation, with no manual intervention on the code.
2. CheerpJ works directly on Java bytecode, and does not require access to the Java source code.
3. CheerpJ comes with a full Java SE runtime, inclusive of Swing/AWT. It supports audio, printing, and any other Java SE component. The runtime supports WebAssembly for optimal performance and size.
4. The JavaScript code generated by CheerpJ is highly optimised and garbage-collectible.
5. CheerpJ enables bidirectional Java-JavaScript interoperability. JavaScript libraries, as well as the DOM, can be called and manipulated from Java. Converted Java modules can be invoked from JavaScript.
6. CheerpJ supports Java multi-threading. In addition, it allows to create concurrent applications by using WebWorkers.
Getting Started
-------
You can download CheerpJ for Linux, Windows and macOS on our website (<https://leaningtech.com/cheerpj/>)
To get started with CheerpJ, please refer to the following pages:
1. [CheerpJ Tutorial](https://docs.leaningtech.com/cheerpj/Tutorial)
2. [Getting Started](https://docs.leaningtech.com/cheerpj/Getting-Started)
3. [Command Line Options](https://docs.leaningtech.com/cheerpj/Command-Line-Options)
Demos
------
Several demos of CheerpJ can be found at <https://leaningtech.com/demo/?cheerpjfilter>.
Bugs and Questions
-------
We welcome any feedback and bug report on it through our [Issue Tracking](https://github.com/leaningtech/cheerpj-meta/issues).
You can also find us on [Gitter](https://gitter.im/leaningtech/cheerpj).
CheerpJ is free for non-commerical use and technical evaluation. See [licensing](https://cheerpj.com/licensing/) for details.

View File

@ -1,67 +0,0 @@
# Welcome to Jekyll!
#
# This config file is meant for settings that affect your whole blog, values
# which you are expected to set up once and rarely edit after that. If you find
# yourself editing this file very often, consider using Jekyll's data files
# feature for the data you need to update frequently.
#
# For technical reasons, this file is *NOT* reloaded automatically when you use
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.
# Site settings
# These are used to personalize your new site. If you look in the HTML files,
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.
title: CheerpJ - Documentation
description: >- # this means to ignore newlines until "baseurl:"
Main documentation and tutorials for CheerpJ | the Java solution for the Web.
url: "https://leaningtech.github.io" # the base hostname & protocol for your site, e.g. http://example.com
baserepo: "https://github.com/leaningtech"
baseurl: "/cheerpj-meta" # the subpath of your site, e.g. /blog
logo: "/assets/cheerpj_logo.png" # Change to relevant file
tagline:
line1: "CheerpJ - the Java solution for the Web"
line2: "Documentation & Tutorials"
social_links:
twitter: leaningtech
github: leaningtech
medium: leaningtech
linkedin: leaning-technologies-Ltd
download: "https://leaningtech.com/download-cheerpj/"
licence: "https://leaningtech.com/cheerpj-licensing/"
demo: "https://leaningtech.com/demo/?cheerpjfilter"
# Build settings
markdown: kramdown
remote_theme: leaningtech/leaningtech-docs
plugins:
- jekyll-seo-tag
defaults:
- scope:
path: ""
values:
image: "https://opengraph.githubassets.com/0695f40a0d2d9ee5d8871e5f80042de3b061f7496b092d086712709c9d0f1a6e/leaningtech/cheerpj-meta"
repository: https://github.com/leaningtech/cheerpj-meta
website: https://leaningtech.com/cheerpj/
issues: https://github.com/leaningtech/cheerpj-meta/issues
chat: https://gitter.im/leaningtech/cheerpj
blog: https://medium.com/leaningtech
has_about: true
# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
# to override the default setting.
# exclude:
# - Gemfile
# - Gemfile.lock
# - node_modules
# - vendor/bundle/
# - vendor/cache/
# - vendor/gems/
# - vendor/ruby/

View File

@ -1,5 +0,0 @@
<ul>
{%- if site.download -%}<li><a href="{{site.download}}">Download</a></li>{%- endif -%}
{%- if site.licence -%}<li><a href="{{site.licence}}">Licencing</a></li>{%- endif -%}
{%- if site.demo -%}<li><a href="{{site.demo}}">Demo</a></li>{%- endif -%}
</ul>

View File

@ -1,22 +0,0 @@
<ul>
<li><a href="{{site.baseurl}}/">Home</a></li>
<li><a href="{{site.baseurl}}/pages/Getting-Started">Getting started</a>
<ul>
<li><a href="{{site.baseurl}}/pages/Tutorial">Tutorial</a></li>
</ul>
</li>
<li><a href="{{site.baseurl}}/pages/CheerpJ-demos">Demos</a></li>
<li><a href="{{site.baseurl}}/pages/Command-Line-Options">Command line options</a></li>
<li>APIs
<ul>
<li><a href="{{site.baseurl}}/pages/Runtime-API">Runtime API</a></li>
<li><a href="{{site.baseurl}}/pages/WebWorker-API">WebWorker API</a></li>
<li><a href="{{site.baseurl}}/pages/Startup-time-optimization">Startup time optimization</a></li>
<li><a href="{{site.baseurl}}/pages/File-System-support">File System support</a></li>
<li><a href="{{site.baseurl}}/pages/DOM-and-JavaScript-interoperability">DOM and JavaScript interoperability</a></li>
<li><a href="{{site.baseurl}}/pages/Implementing-Java-native-methods-in-JavaScript">Implementing Java native methods in JavaScript</a></li>
</ul>
</li>
<li><a href="{{site.baseurl}}/pages/Changelog">Changelog</a></li>
<li><a href="{{site.baseurl}}/pages/Frequently-Asked-Questions">FAQs (Frequently asked questions)</a></li>
</ul>

View File

@ -1,9 +0,0 @@
---
layout: page
title: About
---
This is the place where you will find documentations and tutorials for CheerpJ.
Should some information be missing, incorrect or partial, either get in contact through Gitter / GitHub issues or directly propose a fix.
Following the pencil-shaped links should lead to the markdown version of the relative page, and you are encouraged to file a PR to propose improvments.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 369 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

53
assets/logotype.svg Normal file
View File

@ -0,0 +1,53 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 345.02 89.83" height="36">
<defs>
<style>
.cls-1{fill:#231f20;}.cls-2{fill:#ff7c00;}.cls-3{fill:#e2e2e2;}.cls-4{fill:#ff910d;}.cls-5{fill:#fff;}
@media (prefers-color-scheme: dark) {
.cls-1 { fill: #ffffff; }
}
</style>
</defs>
<g id="Layer_2" data-name="Layer 2">
<g id="Layer_1-2" data-name="Layer 1">
<g id="code_html5">
<path class="cls-1"
d="M131.13,64.23a19.72,19.72,0,0,1-14.21,6,20.07,20.07,0,1,1,14.13-34.36l-5.3,5.38a12.51,12.51,0,1,0-8.83,21.36,12.1,12.1,0,0,0,8.91-3.7Z"
transform="translate(0 -5.54)" />
<path class="cls-1"
d="M172.53,70.25h-7.1V50.1c0-7-5.28-12.52-11.77-12.52S142,43,141.89,49.94V70.17h-7.1v-60h7.1v24.4a18.08,18.08,0,0,1,11.77-4.41c10.41,0,18.79,8.91,18.87,20Z"
transform="translate(0 -5.54)" />
<path class="cls-1"
d="M216,50.26a19.91,19.91,0,1,1-3.53-11.56l-22.4,22.48a12.88,12.88,0,0,0,5.78,1.45A12.43,12.43,0,0,0,208.5,50.26ZM184.81,55.8l16.86-16.86a13.07,13.07,0,0,0-5.78-1.36,12.39,12.39,0,0,0-12.36,12.68A13.05,13.05,0,0,0,184.81,55.8Z"
transform="translate(0 -5.54)" />
<path class="cls-1"
d="M257.47,50.26a19.91,19.91,0,1,1-3.53-11.56l-22.4,22.48a12.88,12.88,0,0,0,5.78,1.45,12.43,12.43,0,0,0,12.61-12.37ZM226.24,55.8,243.1,38.94a13.07,13.07,0,0,0-5.78-1.36A12.39,12.39,0,0,0,225,50.26,13.05,13.05,0,0,0,226.24,55.8Z"
transform="translate(0 -5.54)" />
<path class="cls-1"
d="M261,70.25V30.51h7.55V34.6a20,20,0,0,1,12.53-4.41v7.55a12.49,12.49,0,0,0-12.53,12.52v20Z"
transform="translate(0 -5.54)" />
<path class="cls-1"
d="M281.64,50.26a20,20,0,1,1,20,20,19.65,19.65,0,0,1-12.44-4.33v23.6h-7.55Zm32.52,0a12.49,12.49,0,1,0-25,0v.08a12.49,12.49,0,1,0,25-.08Z"
transform="translate(0 -5.54)" />
<path class="cls-2"
d="M336.14,30.73h7.52V69.45a20,20,0,0,1-20,20V81.93a12.44,12.44,0,0,0,12.48-12.48Zm3.76-6.16A5.12,5.12,0,1,1,345,19.45,5.16,5.16,0,0,1,339.9,24.57Z"
transform="translate(0 -5.54)" />
<polygon class="cls-2"
points="79.37 0 39.69 0 39.69 0 0 0 7.44 80.69 39.69 89.83 39.69 89.83 39.69 89.83 39.69 89.83 39.69 89.83 71.92 80.69 79.37 0" />
<path class="cls-3"
d="M44.83,31.79a19,19,0,0,1,11.75,3.69c.33.25.65.53,1,.81a1.52,1.52,0,0,1,.52,1.61,1.66,1.66,0,0,1-1.3,1.17c-1.86.58-3.76,1.08-5.56,1.82a32.11,32.11,0,0,0-11.7,8.46,29.77,29.77,0,0,1-17.15,9.7,9.32,9.32,0,0,1-1.06.15,1.51,1.51,0,0,1-1.63-1.1,14.73,14.73,0,0,1-.61-6.75,19.3,19.3,0,0,1,7.2-12.21,31.5,31.5,0,0,1,14.93-7c.54-.09,1.09-.16,1.63-.21C43.56,31.85,44.31,31.82,44.83,31.79Z"
transform="translate(0 -5.54)" />
<path class="cls-3"
d="M36.75,70.88c-4.69-.06-8.59-1.14-12-3.84-.29-.23-.57-.49-.85-.74a1.63,1.63,0,0,1-.62-1.77,1.77,1.77,0,0,1,1.39-1.23c1.84-.59,3.7-1.12,5.47-1.87a32.68,32.68,0,0,0,11.8-8.89A29.35,29.35,0,0,1,59.62,42.47a1.65,1.65,0,0,1,2.14,1.4,17.05,17.05,0,0,1-1.93,13.71,25.1,25.1,0,0,1-8.78,8.66,29.94,29.94,0,0,1-11.48,4.37C38.48,70.76,37.38,70.82,36.75,70.88Z"
transform="translate(0 -5.54)" />
<polygon class="cls-4"
points="39.86 7.62 39.86 84.04 39.86 84.04 66.14 76.64 72.55 7.62 39.86 7.62" />
<path class="cls-5"
d="M56.45,36.36c-.32-.28-.66-.55-1-.81a20.41,20.41,0,0,0-12.28-3.68c-.55,0-1.33.06-2.1.12a7.53,7.53,0,0,0-1.05.22c-.28,0,.83.11-.15.16V48.46c3.94-3.2,6.28-5.79,10.63-7.49,1.88-.74,3.54-1.25,5.49-1.83A1.48,1.48,0,0,0,57.16,38,1.55,1.55,0,0,0,56.45,36.36Z"
transform="translate(0 -5.54)" />
<path class="cls-5"
d="M61,45.06a1.64,1.64,0,0,0-2.14-1.35,29.37,29.37,0,0,0-17.59,9.7c-.5.55-.46,1.07-1.44,1.59V70.68a29.57,29.57,0,0,0,10.55-4.07,24.48,24.48,0,0,0,8.73-8.34A15.87,15.87,0,0,0,61,45.06Z"
transform="translate(0 -5.54)" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="94" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h27v20H0z"/><path fill="#4c1" d="M27 0h67v20H27z"/><path fill="url(#b)" d="M0 0h94v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"><text x="145" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.0</text><text x="145" y="140" transform="scale(.1)" textLength="170">1.0</text><text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="570">changelog</text><text x="595" y="140" transform="scale(.1)" textLength="570">changelog</text></g> </svg>

Before

Width:  |  Height:  |  Size: 950 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="94" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h27v20H0z"/><path fill="#4c1" d="M27 0h67v20H27z"/><path fill="url(#b)" d="M0 0h94v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"><text x="145" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.1</text><text x="145" y="140" transform="scale(.1)" textLength="170">1.1</text><text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="570">changelog</text><text x="595" y="140" transform="scale(.1)" textLength="570">changelog</text></g> </svg>

Before

Width:  |  Height:  |  Size: 950 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="94" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h27v20H0z"/><path fill="#97CA00" d="M27 0h67v20H27z"/><path fill="url(#b)" d="M0 0h94v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="145" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.2</text><text x="145" y="140" transform="scale(.1)" textLength="170">1.2</text><text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="570">changelog</text><text x="595" y="140" transform="scale(.1)" textLength="570">changelog</text></g> </svg>

Before

Width:  |  Height:  |  Size: 954 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="94" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="94" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h27v20H0z"/><path fill="#97CA00" d="M27 0h67v20H27z"/><path fill="url(#b)" d="M0 0h94v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="145" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.3</text><text x="145" y="140" transform="scale(.1)" textLength="170">1.3</text><text x="595" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="570">changelog</text><text x="595" y="140" transform="scale(.1)" textLength="570">changelog</text></g> </svg>

Before

Width:  |  Height:  |  Size: 954 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="78" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h51v20H0z"/><path fill="#4c1" d="M51 0h27v20H51z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"><text x="265" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">cheerpj</text><text x="265" y="140" transform="scale(.1)" textLength="410">cheerpj</text><text x="635" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.0</text><text x="635" y="140" transform="scale(.1)" textLength="170">1.0</text></g> </svg>

Before

Width:  |  Height:  |  Size: 946 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="78" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h51v20H0z"/><path fill="#4c1" d="M51 0h27v20H51z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"><text x="265" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">cheerpj</text><text x="265" y="140" transform="scale(.1)" textLength="410">cheerpj</text><text x="635" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.1</text><text x="635" y="140" transform="scale(.1)" textLength="170">1.1</text></g> </svg>

Before

Width:  |  Height:  |  Size: 946 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="78" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h51v20H0z"/><path fill="#97CA00" d="M51 0h27v20H51z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="265" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">cheerpj</text><text x="265" y="140" transform="scale(.1)" textLength="410">cheerpj</text><text x="635" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.2</text><text x="635" y="140" transform="scale(.1)" textLength="170">1.2</text></g> </svg>

Before

Width:  |  Height:  |  Size: 950 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="78" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="78" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h51v20H0z"/><path fill="#97CA00" d="M51 0h27v20H51z"/><path fill="url(#b)" d="M0 0h78v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="265" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">cheerpj</text><text x="265" y="140" transform="scale(.1)" textLength="410">cheerpj</text><text x="635" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">1.3</text><text x="635" y="140" transform="scale(.1)" textLength="170">1.3</text></g> </svg>

Before

Width:  |  Height:  |  Size: 950 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,159 +0,0 @@
---
title: Changelog
---
version 2.3 - April 29th, 2022:
* Improved legacy code generation
* Improved clipboard support
* Improved exceptions for I/O handling
* Add proper support to Synchronized methods
* Made async fetch the default for any file
* Minor fixes to AWT components
Version 2.2 - May 14th, 2021:
* Optimized exception handling
* Extended JNI support
* Improved file system emulation
* Improved HTTP networking support
* Improved AWT support
* Improved audio support
* Improved reflection support
* Improved applet parsing robustness
* Improved correctness of 32-bit floating point
* Improved correctness of class private methods
Version 2.1 - April 3rd, 2020
* Optimized exception handling
* Optimized reflection calls
* Improved AWT support
* Improved robustness of the AOT compiler
* Further improvements to native Java reflection support
* Improved JavaScript interaction robustness
* Fixed support for --stub-natives in cheerpjfy.py
* Code size improvements
Version 2.0 - February 4th, 2020
* Introduction of WebAssembly runtime modules
* Extended file system support to read, write and delete (IndexedDB backend)
* New read-only filesystem in /str/ for Strings or binary data
* Improved event handling, mouse interaction and focus
* Extend support for charsets
* Improved robustness to invalid classes often present in real-world JAR archives
* Improved isolation of CheerpJ symbols
* Improved support to multi-threading, in particular Thread.interrupt
* Use the CFGStackifier algorithm to synthesize control flow in generated code
* New API to receive preloading notification (allows to build custom progress bars)
* Improved detection of Applets on HTML pages
* Improved packaging for MacOS
Version 1.4 - April 14th, 2019:
* Support Thread.interrupt
* Improved keycode conversion
* Improved AWT TextArea support
* Improved support for modal dialogs
* Fix support for non-ASCII Java fields
* Fix resolving of default methods from interfaces
* Minor fixes to reflection and code generation
Version 1.3 - November 28th, 2018:
* Significantly faster font rendering
* Full rework of keyboard event handling
* Support unicode output on the console
* Support applets in frames and iframes
* Support multiple applets on a single page
* Improved class loader correctness
* Improved XHR-based HTTP(S) handler
* Improved AWT rendering
* Improved reflection support
* Improved serialization support
* Improved threading correctness
* Improved focus support
* Improved mouse wheel support
Version 1.2 - Sep 6th, 2018:
* Support Copy / Paste to system clipboard
* Support ProGuard config generation
* Support window resizing
* Support sealed packages
* Optimized JNI calls
* Improved correctness of mouse events
* Improved reflection support
* Improved XHR-based HTTP(S) handler
* Improved threading cleanup
Version 1.1 - Jul 23rd, 2018:
* Introduced parallel preloading of resources that are known to be needed before starting the application (useful in production);
* New, faster API for JavaScript to Java interoperability based on standard promises (allowing async/await)
* Exception handling when calling Java from JavaScript
* Improved support for reflection
* Improved code generation, particularly for low-level graphical routines
* Improved HTTP/HTTPs connections
* Support for time zones
* Improved startup time
* Support for custom cursors
Version 1.0 - Mar 20th, 2018:
* Full rework of filesystem support
* Support Drag-and-Drop
* Support Java clipboard
* Support multi-window applets
* Support WebWorkers
* Support printing on Edge
* Support JPEG writing
* Improved input handling
* Improved applet support
* Improved AWT support
* Improved JNLP support
* Improved HTTP support
* Improved reflection support
* Improved audio support
* Reduced runtime size
Version Beta 3 - Nov 11th, 2017:
* Improved printing support with browser native printing
* Full rework of graphical architecture
* Code size optimisations
* Runtime performance optimisations
* Reduced size of the runtime
* Improvements to startup time
* Support for splitting application .jar.js files in multiple packages
* Improved on-the-fly compiler speed (dynamic class generation)
* Inline well-known system methods
* Inline small statically resolved methods
Version Beta 2 - Oct 13th, 2017:
* Support for printing (print to .ps files)
* Initial support for audio (javax audio)
* Support for Internet Explorer 11 and Edge
* Reduced code size - up to 20% size reduction on large applications
* Improved runtime performance
* Optimized 64-bit arithmetic
* Optimized exception handling
* Improved window dragging
* Improved popup support
* Improved filesystem support
* Improved cjNew overload resolution
* Improved thread scheduling
* Improved rendering performance
* Improved reflection performance
* Fixed display area detection
* Fixed keyboard focus handling
Version Beta 1 - Sep 27th, 2017:
* First public release

View File

@ -1,45 +0,0 @@
---
title: Demos
---
To showcase the capabilities of the CheerpJ compiler we have published several demos
## OpenAstexViewer
<https://cheerpjdemos.leaningtech.com/OpenAstexViewer.html>
<img src="{{site.baseurl}}/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, the source code is available here: <https://github.com/openastexviewer/openastexviewer>
## Swing examples:
<https://cheerpjdemos.leaningtech.com/SwingDemo.html>
<img src="{{site.baseurl}}/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.
Source: <https://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html>
## JavaFiddle
<https://javafiddle.leaningtech.com/>
<img src="{{site.baseurl}}/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.
Source: [https://javafiddle.leaningtech.com/index.html] (Inspect the page using the devtools)
## iText Demo
<https://cheerpjdemos.leaningtech.com/iTextDemo.html>
<img src="{{site.baseurl}}/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.
Source: <https://cheerpjdemos.leaningtech.com/itextCheerpJDemo.js>

View File

@ -1,43 +0,0 @@
---
title: Command line options
---
The basic usage of the ```cheerpjfy.py``` build script is:
```
./cheerpjfy.py application.jar
```
The script also accept various command line options to customize the JAR.JS compilation process.
### --help
Shows all the command line options
### -v
Shows the CheerpJ version and the recommend ```loader.js``` to use in deployment
### --deps=DEPSPATHS
List of ```:``` separated JARs that this JAR depends on. Please note that all the listed JAR paths should be either relative to the target JAR or absolute.
### --pack-jar=PACKJAR
Generate a packed version of the input JAR. Debug information and all code are removed.
### -j NUMJOBS
Number of parallel compilation jobs
### --work-dir=WORKDIRPATH
A directory where all the JARs are unpacked. This is useful to speed up multiple compilations of the same JARs and to select a different disk when not enough free space is available in the temporary directory. Keep in mind that the directory passed to the option must be manually created _before_ the command is run.
### --natives=NATIVESPATH
Root of the native JS implementations for classes in this JAR file
### --stub-natives=NATIVESPATH
Generate stubs for all native methods from classes in this JAR. The parameter must be an existing directory, it will be populated with new JavaScript files for each class having native methods. **Note**: Existing files in the passed directory will be overwritten.

View File

@ -1,70 +0,0 @@
---
title: DOM and JavaScript interoperability
---
CheerpJ allows users to interact with the browser DOM directly from Java, without overhead. To achieve this we provide an additional jar (```cheerpj-dom.jar```) in the CheerpJ downloadable archive.
This JAR provides declarations for all of the relevant Java interfaces and classes. In particular you will find them wrapped in the ```com.leaningtech.client``` package, for example the ```Document``` interface of the browser (documented [here](https://developer.mozilla.org/en-US/docs/Web/API/Document)) becomes ```com.leaningtech.client.Document``` with CheerpJ.
The ```com.leaningtech.client.Global``` is a representation of the global namespace in the browser context. It only contains static methods and fields
## Basic example
```java
import com.leaningtech.client.Document;
import com.leaningtech.client.Element;
import com.leaningtech.client.Global;
import com.leaningtech.client.JSString;
public class DomExample
{
public static void main(String[] a)
{
// Retrieve the global document object, it comes from the global namespace of the browser.
Document d = Global.document;
// Retries a known element from the page using it's id
// NOTE: Java Strings must be converted to JavaScript string before being used
Element e = d.getElementById(Global.JSString("existingNode"));
// Currently, setter/getters must be used to access properties
e.set_textContent(Global.JSString("sometext"));
Element newDiv = Global.document.createElement(Global.JSString("p"));
// Initialize the new element with text derived from the previous one
newDiv.set_textContent(e.get_textContent().substring(3).toUpperCase())
// Add it to the document body
Global.document.get_body().appendChild(newDiv);
JSString divContent = newDiv.get_textContent();
// This logs directly to the browser console
Global.console.log(divContent);
}
}
```
## Using Strings
It's important to keep in mind that Java Strings are not JavaScript Strings. To avoid confusion, in CheerpJ the ```JSString``` name is used for the JS version. The static ```Global.JSString``` utility function can be used to create ```JSString```s from Java ```String```s. If a ```JSString``` needs to be used many times it could be useful to cache it. Similarly the ```Global.JavaString``` function can be used to convert back from ```JSString``` to normal Java ```String```.
## Calling JS methods
The ```Global``` class provides a few static methods that can be used to call arbitrary JS functions in the global scope.
```java
public static Object jsCall(String funcName, Object... arg);
public static int jsCallI(String funcName, Object... arg);
public static double jsCallD(String funcName, Object... arg);
public static JSString jsCallS(String funcName, Object... arg);
```
The various methods behave the same, with the only difference being the expected return type. As JavaScript functions are untyped CheerpJ does not have enough information to auto-box the returned values, so you need to use the right return type on the call site. Java Strings parameters will be automatically converted to JavaScript Strings.
## Building the code
Assuming the example above is contained in ```DomExample.java```, you need to first build the program using the standard ```javac``` compiler, create a JAR and then create the JAR.JS from it using CheerpJ. In both steps the ```cheerpj-dom.jar``` must be explicitly added to the command line as a dependency.
```
# The CHEERPJ_INSTALL_PATH is assumed to be set to the location where the CheerpJ archive has been installed
javac -cp $CHEERPJ_INSTALL_PATH/cheerpj-dom.jar DomExample.java
jar cvf domexample.jar DomExample.class
$CHEERPJ_INSTALL_PATH/cheerpjfy.py --deps $CHEERPJ_INSTALL_PATH/cheerpj-dom.jar domexample.jar
```
See the [Getting Started](Getting-Started) page to see how to run the compiled Java code in an HTML page.

View File

@ -1,58 +0,0 @@
---
title: File System support
---
CheerpJ provides full filesystem support for converted Java applications.
Read only and read/write filesystems are exposed in Java and can be used to read, write and manipulate files as normally when running on a JVM.
**Note**: CheerpJ provides access to a virtualized filesystem, which does not correspond to the local computer. Accessing local files from the browser it's forbidden for security reasons.
# File Systems in CheerpJ
CheerpJ implements three main filesystem concepts:
1. A read-only, HTTP-based filesystem
2. A read/write, IndexedDB-based, persistent filesystem
3. A read-only, memory based filesystem
CheerpJ filesystems are implemented as UNIX-style virtual filesystems with multiple mount points. The default mount points are defined as follows:
1. ```/app/``` → An HTTP-based read-only filesystem, used to access JARs and data from your local server.
2. ```/files/``` → An IndexedDB-based, persistent read-write file system
3. ```/lt/``` → Another HTTP-based read-only filesystem, pointing to the CheerpJ runtime
4. ```/str/``` → A read-only filesystem to easily share JavaScript Strings or binary data (an ```Uint8Array```) with Java code
# ```/app/``` mount point
The /app/ mount point corresponds to a virtual read-only, HTTP-based filesystem. ```/app/``` is used to access JAR files and data from your local server.
The ```/app/``` directory is virtual, and only exists inside of CheerpJ. It is required to distinguish files from the local server from runtime files and files stored in the browser database.
The ```/app/``` directory refers to the root of your web server. So, assuming that your web server is available at ```http://127.0.0.1:8080/```, here are some example file mappings:
* ```/app/example.jar``` → ```http://127.0.0.1:8080/example.jar```
* ```/app/subdirectory/example.txt``` → ```http://127.0.0.1:8080/subdirectory/example.txt```
# ```/files/``` mount point
The ```/files/``` mount point corresponds to a virtual read-write, IndexedDB-based filesystem. ```/files/``` is used to store persistent data on the browser client.
The ```/files/``` directory is a virtual concept used by CheerpJ to store and refer to files.
# ```/str/``` mount point
The ```/str/``` mount point is a simple read-only filesystem that can be populated from JavaScript to share data with Java code.
From JavaScript you can add files into the filesystem using the ```cheerpjAddStringFile``` API. Example:
```
cheerpjAddStringFile("/str/fileName.txt", "Some text in a JS String");
```
You can access this data from Java, for example:
```
import java.io.FileReader;
...
FileReader f = new FileReader("/str/fileName.txt")
...
```
The ```cheerpjAddStringFile``` API can be used with JavaScript ```String```s or ```Uint8Array```s. ```Uint8Array```s may be useful to provide binary data to the Java application, for example a user selected file coming from an HTML5 ```<input type="file">``` tag.

View File

@ -1,94 +0,0 @@
---
title: CheerpJ FAQs
---
## What is CheerpJ?
CheerpJ is a solution for converting unmodified Java client applications into browser-based HTML5/JavaScript web applications. CheerpJ consists of an ahead-of-time compiler from Java bytecode to JavaScript, 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, and generates a .jar.js (or .js) output.
## 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.
## 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](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 fileystem 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.

View File

@ -1,108 +0,0 @@
---
title: Getting started
---
This page will help you getting started with CheerpJ and converting your first Java application to JavaScript in no time.
To start, make sure to download the latest available version of CheerpJ [here](https://leaningtech.com/download-cheerpj/). Decompress the Cheerpj 2.3 archive anywhere, for example in ```~/cheerpj_2.3```.
**Important:** Converting an applet is documented at the bottom of this page.
# Converting a single JAR to a JAR.JS file
```cheerpjfy.py``` is an helper script that automatically takes care of unpacking, compiling and optimising a whole JAR archive. Using ```cheerpjfy.py``` is the recommended way of compiling applications and libraries using CheerpJ.
The basic usage is very simple:
```
~/cheerpj_2.3/cheerpjfy.py my_application_archive.jar
```
This command will generate a file called ```my_application_archive.jar.js```, which needs to be deployed in the same folder of the original .JAR archive, and hosted on a web server. Instructions on how to serve the converted JavaScript on a web page are provided below.
**Important:** The files _must_ be accessed through a Web server. Trying to open the HTML page directly from the disk is not supported. The URL must look like ```http://127.0.0.1:8080/cheerpj_test.html```, if it looks like ```file://c/users/Test/cheerpj_test.html``` CheerpJ won't be able to start.
**Note to Windows users:** You will need to have python3 installed on the system. Python provides a launcher called ```py``` that will automatically detect and use the right version of python for a given script. To use ```cheerpjfy.py``` on Windows you need to prefix all the commands with ```py```, for example:
```
py c:\cheerpj_2.3\cheerpjfy.py application.jar
```
# Converting multiple JARs to JAR.JS's files
If your JAR has any dependencies in the form of further JAR archives, the ```cheerpjfy.py``` command line must be modified as follows:
```
~/cheerpj_2.3/cheerpjfy.py --deps my_dependency_archive.jar my_application_archive.jar
```
This command will generate ```my_application_archive.jar.js``` but **not** ```my_dependency_archive.jar.js```. Each archive should be compiled separately by invoking ```~/cheerpj_2.3/cheerpjfy.py my_dependency_archive.jar```.
It is in general safe to put the target JAR in the ```--deps``` list, although it is not required. If you have an application composed of many JARs you can do something like this:
```
for f in one.jar two.jar three.jar
do
~/cheerpj_2.3/cheerpjfy.py --deps one.jar:two.jar:three.jar $f
done
```
# Basic HTML page for testing a Java application
```html
<!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>
```
This page will initialize the CheerpJ system, create a graphical environment to contain all Java windows and then execute the ```main``` method of ```ChangeThisToYourClassName```. The second parameter of cheerpjRunMain is a ```:``` separated list of JARs 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.
You can now serve this web page on a simple http server, such as the http-server utility.
```
http-server ~/cheerpj_2.3/
```
# Converting an applet
Applets can be run by Chrome users using the [CheerpJ Applet Runner](https://chrome.google.com/webstore/detail/cheerpj-applet-runner-bet/bbmolahhldcbngedljfadjlognfaaein) Chrome extension. You can also compile the applet ahead of time using the method described above.
To support all browsers, you can add the following tags to your page:
```
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
<script>cheerpjInit({enablePreciseAppletArchives:true});</script>
```
This should be sufficient to get the applet to run on any browser, with the pre-compiled JAR.JS's files deployed in the same directory of the the original JAR files. The ```cheerpjInit({enablePreciseAppletArchives:true});``` call can be done during page initialization.
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.
# Basic HTML page for testing a Java applet
```
<!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>
```

View File

@ -1,58 +0,0 @@
---
title: Implementing native methods
---
With CheerpJ, it is possible to implement Java 'native' methods (that would normally be implemented in C/C++ or other AOT-compiled language) in JavaScript, similarly to what would be done in regular Java using the Java Native Interface (JNI).
# Java Native Methods
Take as an example the following Java class
```java
public class SomeClass {
public static void someStaticMethod() {
...
}
public float someInstanceMethod() {
...
}
public native int someNativeMethod();
}
```
Java will search for the implementation of ```someNativeMethod``` using the JNI.
When compiling this class with CheerpJ, a JavaScript implementation of this method will need to be provided. Implementing native Java methods in JavaScript can be useful to use browser functionalities that are not currently exposed at the Java level.
# Java Native Methods in CheerpJ
Implementing native methods is simply a matter of adding a JavaScript function in the global scope with a correctly mangled signature.
Since this is a rather involved process, the ```cheerpjfy.py``` script provides functionality to simplify the process by using the ```--stub-natives=destinationDir``` command line option.
Assume the previous class has been compiled and packaged in ```some.jar```, to generate a directory tree for JS native code you can do:
```
mkdir native/
cheerpjfy.py --stub-natives=native/ some.jar
```
This will generate a tree of directories under the ```native``` folder, which will replicate the Java package structure. Each class with at least one native method will generate a ```ClassName_native.js``` stub file with ready to be implemented.
Once all have been implemented, native methods can be packaged with the compiled code using the following command:
```
cheerpjfy.py --natives=native/ some.jar
```
## ```CHEERPJ_COMPRESS(x)``` macro
CheerpJ uses a compression scheme to encode mangled signatures. The ```CHEERPJ_COMPRESS(x)``` macro will encode the argument in parenthesis following such scheme. This macro is used automatically by the ```cheerpjfy.py --stub-natives=``` command, but can also be used manually.
## ```CHEERPJ_SET_CLASS(x)``` macro
Set the current internal class for resolving fields when using ```CHEERPJ_FIELD``` and ```CHEERPJ_STATIC_FIELD``` macros.
## ```CHEERPJ_FIELD(x)``` and ```CHEERPJ_STATIC_FIELD(x)``` macro
The compiler replaces this macro with the encoded field name, it assumes the current class has been set by ```CHEERPJ_SET_CLASS```.

View File

@ -1,340 +0,0 @@
---
title: Runtime API
---
CheerpJ exposes a simple API to interact with a Java application converted to JavaScript. This API can be use to initialise CheerpJ, invoke Java methods, convert data and to enable/disable certain debugging features.
# Integrating an application converted with CheerpJ in a HTML page
A basic HTML file to load a CheerpJ application will look as follows:
```html
<!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("AppClass", "/app/my_application_archive.jar:/app/my_dependency_archive.jar");
</script>
</html>
```
# Loading the CheerpJ runtime
To load the most recent runtime, use the following link:
```html
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
```
More in general, you can use this line:
```html
<script src="https://cjrtnc.leaningtech.com/version/loader.js"></script>
```
where version is the specific runtime version you want to link to.
# cheerpjInit
```cheerpjInit``` must be called once in the page to setup and initialise the CheerpJ runtime environment. ```cheerpjInit``` accepts an optional object argument which can be used to set options.
This method is to be invoked as follows: ```cheerpjInit({option:"value"});```
All the supported options are described below.
## ```clipboardMode```
By default CheerpJ supports an internal clipboard which is local to the Java application and is not integrated with the system clipboard. To change this behaviour you can initialize CheerpJ in the following way:
```
cheerpjInit({clipboardMode:"system"});
```
In ```system``` mode CheerpJ will share the clipboard with the system. Browsers enforce serious limitations on how the system clipboard can be accessed. In practice it is generally accessible when the ```Ctrl+C``` and ```Ctrl+V``` shortcuts are used (```Cmd+C``` and ```Cmd+V``` on MacOSX). Due to these limitations the UX when using ```clipboardMode:"system"``` is:
- ```Ctrl+C```/```Cmd+C```: the user has to press the shortcut twice to give CheerpJ access to the system clipboard. CheerpJ will block the execution while waiting for the second ```Ctrl+C```.
- ```Ctrl+V```/```Cmd+V```: this shortcut behaves normally, there is no difference with native execution.
- Menu based Copy/Paste: ```Ctrl+C```/```Ctrl+V``` are needed to access the clipboard. CheerpJ will block the execution while waiting the appropriate shortcut.
Commercial users adopting this integration have so far reported that this change in UX is not a significant burden for users. Moreover, in the future we plan to add an additional clipboard mode to take advantage of a new permission-based browser API which is currently being standardized. This future mode will provide native like user experience in all cases.
## ```disableErrorReporting```
CheerpJ automatically reports errors at runtime. Setting this option to ```true``` disables this system.
Example:
```
cheerpjInit({disableErrorReporting:true});
```
## ```disableLoadTimeReporting```
CheerpJ automatically get data about loading time. Setting this option to ```true``` disables this system.
Example:
```
cheerpjInit({disableLoadTimeReporting:true});
```
## ```enableInputMethods```
When this option is set to ```true``` CheerpJ will be able to receive text input from the input method framework of the platform. This is useful to support text input for languages such as Chinese, Japanese and Korean.
## ```enableProguardTrace```
When this option is set to ```true``` CheerpJ will automatically keep track of the classes actually used at runtime. Moreover, it will also keep track of classes which are accessed by reflection. After the application has been fully tested you can use the ```cjGetProguardConfiguration()``` function from the browser console to download a proguard configuration file (```cheerpj.pro```) that you can directly use with proguard to remove unneeded classes, methods and fields from the application, greatly reducing the download size and startup time.
## ```javaProperties```
An array of Java properties in the form ```"key=value"```. They will be defined on the System object (System properties). This option should be used if command line arguments in the form ```-Dkey=value``` are required when using native Java.
Example usage:
```
cheerpjInit({javaProperties:["prop1=value1","prop2=value2"]});
```
## ```listener```
An object containing callbacks that CheerpJ will use to report various information to the user. Currently only the ```jsLoadReason``` and ```preloadProgress``` callbacks are supported.
### ```jsLoadReason(scriptName, directReason, userReason)```
**Please note that enabling this listener may have significant performance impact and should not be used in production**
For each new .jar.js to be loaded, CheerpJ will call this function. This can be useful to debug the reason why some parts of the runtime are loaded, if unexpected.
* ```scriptName```: The name of the JS file being loaded
* ```directReason```: A CheerpJ uncompressed and mangled symbol. The method that most directly caused the load. This might not be very useful since it will most often be a ```java.lang.ClassLoader``` method. Can be ```(Internal)``` if it could not be detected.
* ```userReason```: A CheerpJ uncompressed and mangled symbol. The last non-runtime method in the stack before the loading. This should be more useful in understanding the user code that introduces the dependency. Can be ```(Internal)``` if it could not be detected.
Example usage:
```
var cheerpjListener = {jsLoadReason:function(scriptName, directReason, userReason){ ... }};
cheerpjInit({listener:cheerpjListener});
```
### ```preloadProgress(loadedFiles, totalFiles)```
This listener may be used in combination with [[ preloading support | Startup-time-optimization#Preload-resources ]] to monitor the loading of an application. The information provided is useful, for example, to display a loading/progress bar.
* ```loadedFiles```: How many files have been preloaded so far
* ```totalFiles```: How many files needs to be preloaded in total. This number may increment during the loading phase. CheerpJ has a prediction mechanism and may preload additional resources depending on application behaviour
Example usage:
```
function showPreloadProgress(loadedFiles, totalFiles)
{
console.log("Percentage loaded "+(loadedFiles*100/totalFiles));
}
var cheerpjListener = {preloadProgress:showPreloadProgress};
cheerpjInit({listener:cheerpjListener});
```
## ```logCanvasUpdates```
When set to ```true```, it enables logs on the console about the display areas which are being updated. Useful to debug overdrawing.
Example:
```
cheerpjInit({logCanvasUpdates:true});
```
## ```overrideShortcuts```
Some applications needs to internally handle keyboard shortcuts which are also used by the browser, for example Ctrl+F. Most users expect the standard browser behavior for these shortcuts and CheerpJ does not, by default, override them in any way.
A CheerpJ-converted application can take control of additional shortcuts by providing a callback function as the ```overrideShortcuts``` options of ```cheerpjInit```. This callback receives the ```KeyboardEvent``` coming from the browser and should return ```true``` if the default browser behaviour should be prevented.
Whenever possible we recommend _not_ to use browser reserved shortcuts, to maintain a consistent user experience. In any case, the following limitations apply:
* Some shortcuts (Ctrl+T, Ctrl+N, Ctrl+W) are reserved by the browser and never received by the page itself. These _cannot_ be overridden
* Overriding (Ctrl+C/Ctrl+V) will prevent ```clipboardMode:"system"``` from working correctly.
Example:
```
cheerpjInit({overrideShortcuts:function(e)
{
// Let Java handle Ctrl+F
if(e.ctrlKey && e.keyCode == 70)
return true;
return false;
}});
```
## ```preloadResources```<a name="preloadResources"></a>
By using ```preloadResources```, you can provide CheerpJ with a list of runtime files which you know in advance will be required for the specific application. The list should be given as a JavaScript array of strings.
Example:
```
cheerpjInit({preloadResources:["/lts/file1","/lt/file2"]});
```
See also [cjGetRuntimeResources](#cjGetRuntimeResources).
## ```status```
This option determines the level of verbosity of CheerpJ in reporting status updates.
* ```"default"```: Enables status reporting during initialization and short-lived "Loading..." messages every time new runtime code is being downloaded.
* ```"splash"```: Enabled status reporting only during initialization. There will be no feedback after the first window is shown on screen.
* ```"none"```: Disable all status reporting.
## ```appletParamFilter```
Some applications may need to have some parameter modified before getting those inside the applet.
Example:
```
cheerpjInit({appletParamFilter:function(name, value)
{
if(name==="httpServer")
return value.replace("http", "https");
return value;
}});
```
# cheerpjCreateDisplay
This method will create the HTML element that will contain all Java windows. It is only required to run graphical applications.
```cheerpjCreateDisplay(width, height, /*optional*/parent)```
The ```width``` and ```height``` parameter represent the display area size in CSS pixels. It is also possible to specify a parent element if required, if a parent element is not specified the display area will be appended to the page ```body``` element. If a parent is specified it is also possible to pass ```-1``` to both ```width``` and ```height```, in that case the size will correspond to the parent size and it will also change dynamically if the parent is modified by either CSS changes or browser window resize.
# Running applications and JARs
**Warning**: CheerpJ does not support opening the HTML pages directly from disk. If the URL in your browser starts with ```file://```, CheerpJ will not run. You _must_ use a local Web server.
The most common way of starting an application is to use the ```cheerpjRunMain``` API, which lets you execute the static main method of a Java class in the classpath.
```
cheerpjRunMain("fully.qualified.class.name", "/app/my_application_archive.jar:/app/my_dependency_archive.jar", arg1, arg2);
```
Alternatively, if your JAR is designed to be executed with ```java -jar my_application_archive.jar```, you can use this simpler API.
```
cheerpjRunJar("/app/my_application_archive.jar", arg1, arg2);
```
Optionally, if your JAR also need additional dependencies, you can use.
```
cheerpjRunJarWithClasspath("/app/my_application_archive.jar", "/app/my_dependency_archive.jar", arg1, arg2);
```
In all cases the arguments should be JavaScript Strings.
# cjCall / cjNew
These functions make it possible to conveniently call Java code from JS. Java code is always run asynchronously, so the returned values are ```Promise```s. See below for details.
Calling Java constructors from JavaScript:
```JavaScript
/* Equivalent Java code: myClass object = com.my.Java.package.myClass(argument1) */
var object = cjNew("com.my.Java.package.myClass", argument1);
```
Call static Java methods from JavaScript:
```JavaScript
/* Equivalent Java code: int returnVal = com.my.Java.package.myClass.method(argument1, argument2, argument3); */
var returnVal = cjCall("com.my.Java.package.myClass", "method", argument1, argument2, argument3);
```
Call Java methods from JavaScript:
```JavaScript
/* Equivalent Java code: int returnVal = object.method(argument1, argument2, argument3); */
var returnVal = cjCall(object, "method", argument1, argument2, argument3);
```
Both ```cjNew``` and ```cjCall``` return standard JavaScript ```Promise```s. They can be transparently used in other calls to ```cjNew/cjCall``` or you can use ```.then(...)``` and ```.catch(...)``` to access the resulting value and handle errors. It is also possible to use ```async/await``` (either natively or through a JS transpiler) to write sync-like code using ```cjNew/cjCall``` as async primitives.
## cjResolveCall / cjResolveNew
Using ```cjCall/cjNew``` is convenient, but under the hood Java reflection APIs are used, which may have a significant performance impact if used heavily. If you plan to use ```cjCall/cjNew``` many times it is convenient to go through reflection APIs only once by using the ```cjResolveCall/cjResolveNew``` API.
Examples:
```JavaScript
var promise1 = cjResolveCall("com.something.ClassName", "methodName", ["java.lang.String", "int", "double"]);
var promise2 = cjResolveNew("com.something.ClassName", ["java.lang.String", "int", "double"]);
```
```cjResolveCall``` supports both instance and static methods of classes. The third parameter (for both APIs) is an array of Java types and it is only required if the methodName is not unique in the class (i.e. it is overloaded). The third parameter can be omitted (be null) if the method name (or constructor) is unique. For example:
```JavaScript
var promise = cjResolveCall("com.something.ClassName", "uniqueMethodName", null);
```
```cjResolveCall/cjResolveNew``` are async, like most of CheerpJ's APIs. To get the actual result you can either use .then() or the async/await functionality of JS. For example:
```JavaScript
var resolvedMethod = await cjResolveCall("com.something.ClassName", "uniqueMethodName", null);
cjResolveCall("com.something.ClassName", "uniqueMethodName", null).then(function(resolvedMethod) { ... });
```
The returned value is an opaque handle to the desired method (or constructor), which can now be called an arbitrary number of times without going through Java reflection.
```JavaScript
cjCall(resolvedMethod, arg1, arg2, arg3);
cjNew(resolvedConstructor, arg1, arg2, arg3);
```
Alternatively resolvedMethod can also be used _directly as a function_, for example:
```JavaScript
resolvedMethod(arg1, arg2, arg3);
```
Please note that this convenient form can unfortunately only be used on the main thread, not on Workers. For more information see [WebWorker API](https://docs.leaningtech.com/cheerpj/WebWorker-API)
# Data conversion
## cjStringJavaToJs(str) / cjStringJsToJava(str)
```JavaScript
var jsString = cjStringJavaToJs(javaString);
```
This converts a Java string into a JavaScript string. This operation implies a copy.
```java
String javaString = cjStringJStoJava(jsString);
```
This converts a JavaScript string into a Java string. This operations also implies a copy. String parameters passed to ```cheerpjRunMain```, ```cjCall``` and ```cjNew``` are automatically converted so it is not necessary to use this methods in that case.
## cjTypedArrayToJava
Converts a TypedArray to a Java compatible primitive array. This operation implies a copy. Data is converted as follows:
| Typed Array | Java array |
| ----------- | ---------- |
| Int8Array | byte[] |
| Uint8Array | byte[] |
| Int16Array | short[] |
| Uint16Array | char[] |
| Int32Array | int[] |
| Uint32Array | int[] |
| Float32Array| float[] |
| Float64Array| double[] |
# Preloading APIs
## cjGetRuntimeResources<a name="cjGetRuntimeResources"></a>
Returns a JavaScript string representing the data that should be passed to [preloadResources](#preloadResources). It is a list of files that have been loaded from the runtime up to the time this function is called.

View File

@ -1,73 +0,0 @@
---
title: Startup time optimization
---
This page is a collection of different steps to reduce the startup time of a Java application converted with CheerpJ.
# Overview
Traditionally, users had to have Java preinstalled on their computer in order to run Java applications and applets. CheerpJ converts Java to HTML5/JavaScript, allowing to run applications and applets on browser without users having to install any additional dependency on their computer. Similarly to their JVM counterparts, applications converted to JavaScript with CheerpJ require runtime components to be loaded during execution. In CheerpJ, runtime components are JavaScript modules that are loaded on demand, only if required.
The CheerpJ runtime is highly optimised to minimise the total download size of an 'average' application, totalling 10-20MB of data for a typical download (as a point of comparison, the approximate size of the Java runtime installer is over 60MB). All downloaded components of CheerpJ are cached by the browser, which reduces the download time in subsequent executions of a same application.
This page provides a list of recommendations to reduce the one-time download size, and the resulting application first startup time.
# Gzip compression of JavaScript on server
In our experience it is not uncommon to see that most of the loading time is spent downloading the main ```jar.js``` file for the application (i.e. not from the runtime). **It is critical that the Web server on which your application is deployed has gzip compression enabled for the application's JavaScript files**.
If you are self-hosting the CheerpJ runtime (most likely you will not), please make sure to enable compression on these components as well. The CheerpJ cloud runtime has compression enabled by default.
# Use ProGuard to remove unused code
ProGuard is an industry standard open-source tool to optimize and obfuscate Java bytecode. ProGuard, by itself, can automatically trace the classes used from the application entry point and automatically remove unused classes, methods and field. This can enable a very significant reduction of download size and startup time, especially with applications using multiple third party libraries.
Since Java allows reflection at runtime, ProGuard may end up removing code which is actually used, causing unexpected errors. To help in this scenario CheerpJ supports a special option:
```cheerpjInit({enableProguardTrace:true})```
When initialized with this option CheerpJ will keep track of the classes used at runtime, including classes which are accessed via reflection. Follow these steps to safely optimize an application using proguard.
1. Build a single ```uber-JAR``` by merging the application and dependencies
2. Convert the new JAR to JS using ```cheerpjfy.py```
3. Run the application using CheerpJ with the ```enableProguardTrace:true``` option
4. Fully test the application, making sure that all possible scenarios are executed and all needed classes are loaded
5. From the browser console call ```cjGetProguardConfiguration()```, a proguard configuration file (```cheerpj.pro```) will be automatically generated and downloaded
6. Run ```proguard``` on the ```uber-JAR``` using the generated configuration file to generate a smaller JAR with only the needed classes. ```proguard -dontwarn -injars uber.jar -outjars uber-stripped.jar -libraryjars ~/cheerpj_1.2/rt.jar @cheerpj.pro```
7. Convert this new JAR using ```cheerpjfy.py```
# Reduce the size of the JAR file
```cheerpjfy.py``` supports a command line option (```--pack-jar```) to generate a minimised JAR for deployment.
This smaller JAR is stripped of all original Java bytecode and can no longer be used to run the application on the JVM. The JAR is however necessary for CheerpJ to support Java reflection.
More details are available [here](Command-Line-Options#--pack-jarpackjar)
# Preload resources
CheerpJ cannot predict which runtime resources will be required by an arbitrary application. CheerpJ runtime resources are therefore loaded on demand, one after the other, depending on the requirements of the application at run time.
To take advantage of parallel downloads, and reduce download and startup time of a specific application in production, CheerpJ allows to pre-specify a list of resources (CheerpJ runtime modules) to be loaded at startup.
This list of resources is to be specified manually when starting the CheerpJ environment in an HTML page. We also provide a simple profiling tool to automatically record and output a list of used resources during the execution of an application.
By combining the use of this profiler together with the preloader, one can highly optimise the initial download and startup time of a converted application. Taking advantage of this is a simple 2-step process:
1. Run the application normally using CheerpJ. After the application is loaded, open the JavaScript console of the browser (e.g. Ctrl+Shift+I on many browsers), and type:
```cjGetRuntimeResources()```
The result will look like this:
```["/lts/file1","/lt/file2"]```
The JavaScript console may enclose the string between quotes (```"```), which you should ignore. See [here](Runtime-API#cjgetruntimeresources) for more information.
2. Modify the CheerpJ integration to enable preloading. You will only need to change the ```cheerpjInit``` call, to pass the ```preloadResources``` option. For example:
```cheerpjInit({preloadResources:["/lts/file1","/lt/file2"]});```
See [here](Runtime-API#preloadresources) for more information.
When preloading is enabled CheerpJ will be able to download multiple resources in parallel with the execution of the program. This will greatly improve loading time.

View File

@ -1,90 +0,0 @@
---
title: Tutorial
---
CheerpJ is very easy to use, this tutorial will guide you step by step into compiling an unmodified JAR file to a JAR.JS file. We will also create a basic HTML file integrated with the CheerpJ loader to run the Java application in the browser.
# Download and install CheerpJ
Visit [our download page](https://leaningtech.com/download-cheerpj/) and download the CheerpJ archive for your platform. CheerpJ is available for Linux, Mac OS X and Windows.
CheerpJ is distributed as an archive for all the platforms, you can unpack the archive anywhere in the system. During the tutorial we will assume that CheerpJ has been unpacked in the home directory and its root is ```~/cheerpj_2.3/```. Please keep in mind to use a different path in the following commands if you have chosen a different position or you are using a different version of CheerpJ.
# Build or download the JAR file
CheerpJ compiles unmodified JAR files to JavaScript so that they can run 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. For this example we will download a basic Swing example. Download the [TextDemo.jar](https://docs.oracle.com/javase/tutorialJWS/samples/uiswing/TextDemoProject/TextDemo.jar) file into a new directory. Below we will assume that this new directory is ```~/cheerpj_tutorial/```
# Build the JAR.JS file
CheerpJ provides a convenient python program to convert whole JARs to JavaScript: ```cheerpjfy.py```. It supports several options for advanced users, but it's basic syntax is very simple. The following command will generate ```TextDemo.jar.js```
```
cd ~/cheerpj_tutorial/
~/cheerpj_2.3/cheerpjfy.py TextDemo.jar
```
**NOTE**: ```cheerpjfy.py``` it's a python3 program, you need to have python3 installed on your system.
**NOTE**: On windows you should prefix the command with the ```py``` launcher to use the correct version of python.
# Create an HTML page
Copy the following HTML code into ```~/cheerpj_tutorial/cheerpj_tutorial.html```
```
<!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);
cheerpjRunJar("/app/TextDemo.jar");
</script>
</html>
```
Let's break down what is going on:
* We first include the CheerpJ loader from our cloud runtime. (https://cjrtnc.leaningtech.com/2.3/loader.js). This file is the only script that needs to be loaded to use CheerpJ. CheerpJ will _automatically_ load all other files, including the ```TextDemo.jar.js``` we generated above.
* We initialize CheerpJ using the ```cheerpjInit()``` API. See [Runtime API](Runtime-API) for more information.
* We want to run a graphical application (i.e. a Swing or AWT application), so we need to initialize a _virtual display_ in the page. CheerpJ will render all Java windows into this display.
* We can now start the JAR file. CheerpJ will _automatically_ download the ```TextDemo.jar.js``` file as soon as the first application class is loaded
***NOTE***: The ```/app/``` prefix use in cheerpjRunJar is something that many first time users find confusing. CheerpJ implements a UNIX style virtual filesystem internally, with several _mount points_. For example
* ```/lt/``` -> CheerpJ cloud runtime
* ```/files/``` -> An IndexedDB based, persistent, file storage
* ```/app/``` -> An HTTP based filesystem, used to access JARs and data from your local server.
The ```/app/``` directory is virtual, it only exists inside of CheerpJ and it's needed to distinguish files from the local server from runtime files and files stored in the browser database. The ```/app/``` directory actually refers to the _root_ of your web server. So, assuming that your web server is available at ```http://127.0.0.1:8080/```, here are some example file mappings:
* ```/app/TextDemo.jar``` -> ```http://127.0.0.1:8080/TextDemo.jar```
* ```/app/subdirectory/data.txt``` -> ```http://127.0.0.1:8080/subdirectory/data.txt```
# Run the application in the browser
To test CheerpJ you _must_ use a local Web Server. Opening the ```cheerpj_tutorial.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.
***TIP***: There are many different Web servers that you can use, and all of them should work. For a quick test we recommand:
* Python2: ```python2 -m SimpleHTTPServer 8080```
* Python3: ```python3 -m http.server 8080```
* NPM (http-server): ```http-server -p 8080```
To run TextDemo.jar in the browser using CheerpJ, do the following
```
cd ~/cheerpj_tutorial/
python3 -m http.server 8080
```
Now open your favourite browser and enter the following URL ```http://127.0.0.1:8080/cheerpj_tutorial.html```. You will see the CheerpJ spinner during a brief loading phase. Then the Java window will appear and it will look identical to the native version.
# The end!
Congratulations, you have successfully compiled and run your first Java application using CheerpJ. For more information, please read our in-depth [Getting Started](Getting-Started) page.

View File

@ -1,113 +0,0 @@
---
title: WebWorker API
---
CheerpJ supports running Java code in the background using WebWorkers. To use this functionality you need to include the ```loader.js``` script as usual. (e.g. ```https://cjrtnc.leaningtech.com/latest/loader.js```). The script exposes the APIs described below. It is allowed, but not necessary, to also use CheerpJ in the main thread at the same time.
All code in a Worker runs in parallel and asynchronously with the main thread. All the methods below return standard JavaScript ```Promise```s, and you can use ```.then(...)```, ```.catch(...)``` and ```async/await``` with them.
We recommend reading the [Runtime API](Runtime-API) documentation before proceeding on this page.
## Creating and initializing a CheerpJ worker
The main entry point for CheerpJ workers is the ```CheerpJWorker``` JS interface. It is a normal JS object and it is possible to instantiate it multiple times.
```
var w = new CheerpJWorker();
w.cheerpjInit().then(function(e) { console.log("CheerpJWorker is ready"); });
```
This starts the WebWorker and initializes CheerpJ in that context. All workers need to be initialized in this way. As a general rule the ```CheerpJWorker``` exposes the same API as CheerpJ in the main thread. You can read details about the main thread API in the [Runtime API](Runtime-API) page.
## Parameters and return values
WebWorkers do not share any memory with the main threads, and all interactions happen through messages. This imposes limitations on the type of data that can be passed around.
|Data type |Limitations |
|--------------------------------------------|--------------------------------------------|
|byte/short/char/int/float/double |Fully supported in params and return values |
|byte[]/short[]/char[]/int[]/float[]/double[]|Fully supported in params and return values |
|JavaScript String |Supported in params, not return values |
|Any Java object |Not supported in params or return values |
Java arrays can either come from another Java method or they can be generated from a JS TypedArray using [cjTypedArrayToJava](Runtime-API#cjtypedarraytojava).
It is possible to move Java arrays from the main thread and others ```CheerpJWorker```s. Please note that Java arrays are not copied, but _transferred_ across contexts. This increases efficiency, but also means that the data is not available any more from the calling thread. If the data needs be preserved you must manually make a copy.
Java Strings, being Java objects, cannot be passed or returned. But JavaScript strings can be used as parameters and will be converted to Java Strings directly in the WebWorker context.
## CheerpJWorker.cheerpjRunMain
Runs a Java main method in the WebWorker context
```
w.cheerpjRunMain("ClassName", classPath, arg1, arg2).then(...)
```
## CheerpJWorker.cjCall
Executes a static Java method in the WebWorker contet
```
w.cjCall("ClassName", "methodName", arg1, arg2).then(...)
```
## CheerpJWorker.cjResolveCall
Uses Java reflection to resolve the method and returns an opaque handle to it. This handle can then be used multiple times without using Java reflection again.
```
w.cjResolveCall("ClassName", "methodName", /*Or array of parameter types if methodName is not unique*/null).then(function(resolvedMethod) { w.cjCall(resolvedMethod, arg1, arg2); ... });
```
# Java API for Workers
CheerpJ exposes a custom API to access this feature directly from Java code. The API is equivalent in terms of capabilities. This API is blocking, so to actually take advantage of concurrency between the main thread and Web Workers it is necessary to use this API from a Java thread.
```java
package com.leaningtech.cheerpj;
public class Worker
{
// Initialize the Worker object, this method is blocking
public Worker();
// Runs the main method of the given class in the Web Worker context, this method is blocking
public void runMain(String className, String classPath, Object... arg);
// Runs the given static method in the Web Worker context, this method is blocking
public Object call(String className, String methodName, Object... arg);
// Same as "call". These should be used when primitives are expected.
public int callI(String className, String methodName, Object... arg);
public double callD(String className, String methodName, Object... arg);
public long callL(String className, String methodName, Object... arg);
// Returns an handle to a resolved method, this method is blocking
public Object resolveCall(String className, String methodName, String[] types);
// Run the given resolved method handle in the Web Worker context, this method is blocking
public Object call(Object resolvedFunc, Object... arg);
public int callI(Object resolvedFunc, Object... arg);
public double callD(Object resolvedFunc, Object... arg);
public long callL(Object resolvedFunc, Object... arg);
}
```
The Java version of the API is also extended to support ```long```s in parameters and returned values. Currently they are converted to native JS values when passed to Workers, so their range is limited to +/-2^52.
Example usage:
```java
import com.leaningtech.cheerpj.Worker;
public class WW
{
public static void main(String[] args)
{
Worker w = new Worker();
w.runMain("Hello", "");
}
}
```
To build the class you need to add ```cheerpj-public.jar``` to the classpath
```
javac -cp cheerpj_install_dir/cheerpj-public.jar WW.java
```