Applications can be deployed from any standard web server. Java Web Start leverages existing internet technology, such as the HTTP protocol and web servers, so existing infrastructure for deploying HTML-based content can be reused to deploy Java Technology-based applications using Java Web Start.
To deploy your application to client machines, ensure that all files that
contain your application are accessible through a web server. This typically
requires copying one or more JAR files and a JNLP file into the web server's
directories. Enabling the website to support Java Web Start is similar to
deploying HTML-based content. In addition, to use Java Web Start, the web server
must be configured to support the application/x-java-jnlp-file
MIME type.
Step 1: Configure the web server to use the Java Web Start MIME type.
Many web servers come with the Java Web Start MIME type configured by default. If your web server does not, configure it so that all files with the .jnlp
file extension are set to the application/x-java-jnlp-file
MIME type.
Most web browsers use the MIME type returned with the contents from the web server to determine how to handle the particular content. The server must return the application/x-java-jnlp-file
MIME type for JNLP files in order for Java Web Start to be invoked.
Each web server has a specific way in which to add MIME types. For example, for the Apache web server, you add the following line to the .mime.types
configuration file:
application/x-java-jnlp-file JNLP
Check the documentation for the specifics of your web server.
Step 2: Create a JNLP file for the application.
The easiest way to create this file is to modify an existing JNLP file with your requirements. A simple JNLP file is shown in the following example:
<?xml version="1.0" encoding="utf-8"?> <jnlp spec="8.0+" codebase="http://example.com/demos/helloworld" href="HelloWorld.jnlp"> <information> <title>HelloWorld</title> <description>HelloWorld demo application</description> </information> <resources> <j2se version="1.8+"/> <jar href="HelloWorld.jar" size="47013" download="eager" /> </resources> <application-desc main-class="HelloWorld"/> </jnlp>
The syntax and format for the JNLP file is described in JNLP File Syntax.
Step 3: Make the application accessible on the web server.
Ensure that your application's JAR files and the JNLP file are accessible at the URLs listed in the JNLP file.
Step 4: Create the web page that launches the application.
Create the web page and include one of the following options for starting a Java Web Start application:
Use a link to the JNLP file, as shown in the following examples:
<a href="/some/path/HelloWorld.jnlp">Launch HelloWorld demo</a> <a href="https://docs.oracle.com/javase/tutorialJWS/samples/deployment/dynamictree_webstartJWSProject/dynamictree_webstart.jnlp">Launch DynamicTree demo</a> <a href="http://docs.oracle.com/javase/tutorialJWS/samples/deployment/dynamictree_webstartJWSProject/dynamictree_webstart.jnlp">Launch DynamicTree demo</a>
Use JavaScript, as shown in the following example:
<script src="https://www.java.com/js/deployJava.js"></script> <script> var url = "https://docs.oracle.com/javase/tutorialJWS/samples/deployment/dynamictree_webstartJWSProject/dynamictree_webstart.jnlp"; deployJava.createWebStartLaunchButton(url, '1.6.0'); </script>
Use a link with the jnlp:
schema, as shown in the following example:
<a href="jnlp:https://docs.oracle.com/javase/tutorialJWS/samples/deployment/dynamictree_webstartJWSProject/dynamictree_webstart.jnlp">Launch DynamicTree demo</a>
Copy the JavaScript code from the HTML file generated by the Java Packager tool. See The Java Packager Tool in Java Platform, Standard Edition Deployment Guide.
Java Web Start includes a protocol handler to handle the custom URI schemes
jnlp:
and jnlps:
. Use these schemes as a direct way to
start Java Web Start applications.
The protocol handler is automatically installed on Windows and macOS systems. It must be manually installed on Linux systems.
If you use the Chrome browser on Linux, manually install the protocol handler
that enables you to start Java Web Start applications using the
jnlp
or jnlps
protocol.
In Linux, the xdg-open
command is used to open a file or URL in
the user's preferred application. To install the protocol handler, configure
xdg-open
to use Java Web Start for URLs that include the
jnlp
or jnlps
protocol:
Use a text editor to create a file named javaws.desktop
in the
~/.local/share/applications
directory.
Include the statements shown in the following example.
[Desktop Entry] Encoding=UTF-8 Name=Java(TM) Web Launcher Exec=jre-home/bin/javaws %U Terminal=false Type=Application MimeType=x-scheme-handler/jnlp;x-scheme-handler/jnlps
Save the file.
Run the following commands:
xdg-mime default javaws.desktop x-scheme-handler/jnlp xdg-mime default javaws.desktop x-scheme-handler/jnlps
After installing the protocol handler, Java Web Start is used to launch
applications when the URL contains the jnlp
or jnlps
protocol. For example, the following URL starts the Dynamic Tree sample from the
Java Tutorials:
jnlps://docs.oracle.com/javase/tutorialJWS/samples/deployment/dynamictree_webstartJWSProject/dynamictree_webstart.jnlp
If you use the Firefox browser on Linux, manually install the protocol
handler that enables you to start Java Web Start applications using the
jnlp
or jnlps
protocol.
To install the protocol handler, add properties to the Firefox configuration:
In the address bar in Firefox, enter about:config
.
If you see a page with a warning about voiding your warranty, click I'll be careful, I promise! to continue to the configuration page.
Add a Boolean property.
network.protocol-handler.expose.jnlp
and click OK.The property is added to the configuration.
network.protocol-handler.expose.jnlps
with the value false.When you enter a URL or click a link that uses the jnlp
or
jnlps
protocol, you are prompted to choose the application to use
to open the file. Select Java Web Start Launcher or browse to the
javaws.exe
file in jre-home/bin
.