JNLP apps
Run a working example of a JNLP application or applet
This tutorial will take you step by step on how to run a working example of a JNLP (also known as JWS app) in the browser using CheerpJ.
If you are interested in a ready-to-use tool for running Java Web Start applications, we recommend taking a look at our CheerpJ JNLP Runner browser extension.
This tutorial is divided in two parts:
Prerequisites
For either application or applet, you will need:
- The application
.jnlp
file (given below) - Node.js (>= 18)
- A simple http-server to host your page locally
- A text editor to create and edit an HTML file
- A modern browser like Chrome, Firefox or Safari.
If you already have a JNLP app and you want to go straight to run it in the browser with CheerpJ, we recommend taking a look at our JNLP quickstart tutorial.
JNLP application: SwingSet3
1. The .jnlp
file
We are going to start by looking at the JNLP file. Below, there is an example of an JNLP file for the known demo application SwingSet3. There are three essential elements highlighted:
- The code base: Found as
<jnlp codebase="">
Indicates where the application files will be downloaded from. - The JAR files: Given by the
<jar>
tag in the<resources>
section. - The class name: Given by
main-class
under the<application-desc>
tag. This tag also indicates that the app is a standalone application.
2. Download the application files
Download the application JAR files by manually building their full URL and pasting it in the browser navigation bar. This is done by concatenating the codebase
URL and the jar
URL.
For example:
Do this for all the JARs in the JNLP.
3. Create a project directory
Create a directory where all the files will live. You can choose any name, such as cheerpj-example-swingset3
:
Now create the application structure as shown in the JNLP file. For this example there is a subdirectory called lib
.
Now allocate the application JARs inside this directory following the JNLP directory structure. For this app it will be something like this:
4. Create an HTML file
Inside our project directory cheerpj-example-swingset3
we will create a basic HTML file called index.html
like the following:
What is going on?
- The CheerpJ runtime environment is being integrated at:
cheerpjInit()
initializes the CheerpJ runtime environmentcheerpjCreateDisplay()
creates a graphical environment to contain all Java windows.cheerpjRunJar()
executes the application./app/
is a virtual filesystem mount point that references the root of the web server this page is loaded from.
For this example we are using
cheerpjRunJar()
as the class name is included in the manifest. When this is not the case you can usecheerpjRunMain()
with the main-class name indicated in the JNLP.
5. Host your page locally
To view the example, we need to host the files on a web server. Vite is a convenient tool for this, as it automatically reloads the page when the files change.
Alternatively you can also use the http-server utility:
Visit the address indicated by your http-server in the browser. For example, http://localhost:8080
.
The result
You should be able to see the application running in the browser:
Source code and credits
- View full source code fort this example on GitHub
- SwingSet3 is a demo application by Oracle America, Inc.
JNLP applet: Pitch
We will use the Pitch applet from NASA’s Beginner’s Guide to Aeronautics. This applet shows an interactive animation of an aircraft’s pitch motion. See more.
1. The .jnlp
file
We are going to start by looking at the JNLP file. Below, there is an JNLP example for Pitch applet. There are three essential elements highlighted:
- The code base: Found as
<jnlp codebase="">
Indicates where the application files will be downloaded from. - The JAR files: Given by the
<jar>
tag in the<resources>
section. - The class name: Given by
main-class
under the<applet-desc>
tag. This tag also indicates that the app is an applet.
2. Download the applet file
Download the applet JAR files by manually building the full URL and pasting it in the browser navigation bar. This is done by concatenating the codebase
URL and the jar
URL.
For example:
3. Create a project directory
Create a directory where all the files will live. You can choose any name, such as cheerpj-example-applet
:
Now allocate the application JAR inside this directory following the JNLP directory structure. For this app it will be something like this:
4. Create an HTML file
Inside the project directory, create an HTML file called index.html
like the following:
What is happening?
- The CheerpJ runtime environment is being integrated at:
- The
<cheerpj-applet>
tag contains the applet.jar
location, size and class name. This tag prevents conflicts with native java, the classic<applet>
tag can also be used. cheerpjInit()
initializes the CheerpJ runtime environment.
5. Host your page locally
To view the example, we need to host the files on a web server. Vite is a convenient tool for this, as it automatically reloads the page when the files change.
Alternatively you can also use the http-server utility:
Visit the address indicated by your http-server in the browser. For example, http://localhost:8080
.
The result
You should be able to see the applet running in the browser:
Source code and credits
-
The applet used for this tutorial belongs to the NASA’s Beginner’s Guide to Aeronautics and it is available at their GitHub repository.
Further reading
To continue learning about CheerpJ, visit the reference. If you are interested in a ready-to-use tool for running Java Web Start applications, we recommend taking a look at our CheerpJ JNLP Runner browser extension.