Run a Java applet
Run a java applet in modern browsers
Deprecation noticeCheerpJ 2 is deprecated. Consider migrating to CheerpJ 3 .
CheerpJ can run Java applets in the browser seamlessly. This page will help you getting started with CheerpJ for Java applets.
There are two different ways to run a Java Applet in the browser:
- Running your own Java applet using the CheerpJ runtime environment and the
<cheerpj-applet>
tag in your own webpage. - Running a public applet using the CheerpJ Applet Runner
Chrome extension for applets integrated with the applet tag
<applet>
on public websites.
Running your own applet
You will need:
- Your applet file(s)
- The HTML file where your applet is meant to be displayed.
- A basic HTTP server to test locally
1. Integrating CheerpJ in your HTML file
This tutorial assumes you already have an HTML file with an <applet>
, <object>
or <embed>
tag.
In order to integrate CheerpJ, you just need to add:
- A simple
<script>
within the<head>
of your page with the CheerpJ runtime loader.
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
- A second script calling
cheerpjInit({enablePreciseAppletArchives:true})
to initialize CheerpJβs runtime environment.
<script> cheerpjInit({ enablePreciseAppletArchives: true });</script>
For example:
<!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> <applet archive="Example.jar" code="ExamplePath.ExampleApplet" height="900" width="900" > <p>not able to load Java applet</p> </applet> </body></html>
2. Host your page locally
You can now serve this web page on a simple HTTP server, such as the http-server utility.
npm install http-serverhttp-server -p 8080
In case your users have a native Java plugin installed, you can replace the original HTML tag with a
cheerpj-
prefixed version.<cheerpj-applet>
,<cheerpj-object>
, and<cheerpj-embed>
are all supported.
Running a public applet
1. Install the CheerpJ applet runner
CheerpJ Applet Runner is available for Chrome and Edge.
2. Go to a website with an applet
Visit a page with a Java applet, such as this one and click on the CheerpJ Applet Runner icon in the toolbar and enable CheerpJ.
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.