Introduction to Java Web Start
suggest changeThe Oracle Java Tutorials summarize Web Start as follows:
Java Web Start software provides the power to launch full-featured applications with a single click. Users can download and launch applications, such as a complete spreadsheet program or an Internet chat client, without going through lengthy installation procedures.
Other advantages of Java Web Start are support for signed code and explicit declaration of platform dependencies, and support for code caching and deployment of application updates.
Java Web Start is also referred to as JavaWS and JAWS. The primary sources of information are:
- The Java Tutorials - Lesson: Java Web Start
- Java Web Start Guide
- Java Web Start FAQ
- JNLP Specification
javax.jnlp
API Documentation- Java Web Start Developers Site
Prerequisites
At a high level, Web Start works by distributing Java applications packed as JAR files from a remote webserver. The prerequisites are:
- A pre-existing Java installation (JRE or JDK) on the target machine where the application is to run. Java 1.2.2 or higher is required:
- From Java 5.0 onwards, Web Start support is included in the JRE / JDK.
- For earlier releases, Web Start support is installed separately.
- The Web Start infrastructure includes some Javascript that can be included in a web page to assist the user to install the necessary software.
- The webserver that hosts the software must be accessible to the target machine.
- If the user is going to launch a Web Start application using a link in a web page, then:
- they need a compatible web browser, and
- for modern (secure) browsers, they need to be told how to tell the browser to allow Java to run ... without compromising web browser security.
An example JNLP file
The following example is intended to illustrate the basic functionality of JNLP.
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="https://www.example.com/demo"
href="demo_webstart.jnlp">
<information>
<title>Demo</title>
<vendor>The Example.com Team</vendor>
</information>
<resources>
<!-- Application Resources -->
<j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="Demo.jar" main="true"/>
</resources>
<application-desc
name="Demo Application"
main-class="com.example.jwsdemo.Main"
width="300"
height="300">
</application-desc>
<update check="background"/>
</jnlp>
As you can see, a JNLP file XML-based, and the information is all contained in the <jnlp>
element.
- The
spec
attribute gives the version of the JNPL spec that this file conforms to. - The
codebase
attribute gives the base URL for resolving relativehref
URLs in the rest of the file. - The
href
attribute gives the definitive URL for this JNLP file. - The
<information>
element contains metadata the application including its title, authors, description and help website. - The
<resources>
element describes the dependencies for the application including the required Java version, OS platform and JAR files. - The
<application-desc>
(or<applet-desc>
) element provides information needed to launch the application.
Setting up the web server
The webserver must be configured to use application/x-java-jnlp-file
as the MIMEtype for .jnlp
files.
The JNLP file and the application’s JAR files must be installed on the webserver so that they are available using the URLs indicated by the JNLP file.
Enabling launch via a web page
If the application is to be launched via a web link, the page that contains the link must be created on the webserver.
- If you can assume that Java Web Start is already installed on the user’s machine, then the web page simply needs to contain a link for launching the application. For example.
<a href="https://www.example.com/demo_webstart.jnlp">Launch the application</a>
- Otherwise, the page should also include some scripting to detect the kind of browser the user is using and request to download and install the required version of Java.
NOTE: It is a bad idea to encourage users to encourage to install Java this way, or even to enable Java in their web browsers so that JNLP web page launch will work.
Launching Web Start applications from the command line
The instructions for launching an Web Start application from the command line are simple. Assuming that the user has a Java 5.0 JRE or JDK installed, the simply need to run this:
$ javaws <url>
where <url>
is the URL for the JNLP file on the remote server.