Movatterモバイル変換


[0]ホーム

URL:


CheerpJ
  1. Overview
  2. Getting started
    1. Run a Java Application
    2. Run a Java Applet
    3. Run a Java Library
    4. Run a JNLP
  3. Guides
    1. Intercept external commands
    2. Networking
    3. Resource preloading
    4. Basic Server Setup
    5. Debugging CheerpJ
    6. Filesystem
    7. Implementing Native Libraries
    8. Implementing Native Methods
    9. Library mode
  4. Reference
    1. cheerpjInit
    2. cheerpjRunMain
    3. cheerpjRunJar
    4. cheerpjRunLibrary
    5. cheerpjCreateDisplay
    6. cjFileBlob
    7. cheerpOSAddStringFile
    8. cheerpOSRemoveStringFile
    9. cjGetRuntimeResources
    10. cjGetProguardConfiguration
    11. CJ3Library
  5. Tutorials
    1. Run a Java App in the Browser (SwingSet3)
    2. Run a Java Applet in the Browser (FoilSim)
    3. Run JNLP Apps in the Browser
    4. Swing Browser (Networking)
    5. Server-Client (Networking)
    6. Java and JavaScript Interoperability
  6. Explanation
    1. Files and filesystems
    2. Architecture
  7. Frequently Asked Questions
  8. Migration from CheerpJ 2
  9. Changelog
  10. Licensing
  11. Open Source Copyright Notices
  12. Community showcase

Run a Java Applet

Run a java applet in modern browsers

CheerpJ can run Java applets in the browser seamlessly. This page will help you getting started with CheerpJ for Java applets using the CheerpJ runtime environment on your own webpage.

Not a Developer?

Check out our browser extension for running Java Applets while you browsein modern browsers.

Run Java Applets in your browser.
CheerpJ Applet Runner

Running your own applet

To get started 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.
<scriptsrc="https://cjrtnc.leaningtech.com/4.2/loader.js"></script>
  1. A second script callingcheerpjInit() to initialize CheerpJ’s runtime environment.
<script>
cheerpjInit();
</script>

For example:

index.html
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="utf-8" />
<title>CheerpJ Applet Example</title>
<scriptsrc="https://cjrtnc.leaningtech.com/4.2/loader.js"></script>
</head>
<body>
<applet
archive="Example.jar"
code="ExamplePath.ExampleApplet"
height="900"
width="900"
></applet>
<script>
cheerpjInit();
</script>
</body>
</html>
Java Applets and Java 8
The method ´cheerpJInit´ runs Java 8 by default if the Java version is not specified. Please notice that if you change the version to Java 11 or higher, applets won’t work.

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
npxhttp-server-p8080

In case your users have a native Java plugin installed, you can replace the original HTML tag with acheerpj- prefixed version.<cheerpj-applet>,<cheerpj-object>, and<cheerpj-embed> are all supported.

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
Run a Java Application Run a Java Library

[8]ページ先頭

©2009-2026 Movatter.jp