Run a Java applet

Run a java applet in modern browsers

Deprecation notice
CheerpJ 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 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:

  1. 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>
  1. A second script calling cheerpjInit({enablePreciseAppletArchives:true}) to initialize CheerpJ’s runtime environment.
<script>
cheerpjInit({ enablePreciseAppletArchives: true });
</script>

For example:

index.html
<!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.

Terminal window
npm install http-server
http-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.

Further reading

Was this page helpful?
Suggest changes