Distributing an Application using JavaTM Web Start


Overview. JavaTM Web Start is a technology that allows Java applications to be launched and installed by clicking a link in a web browser. After clicking the link, the application will be downloaded to the user's computer. However, Java Web Start keeps track of the original location of the application, and will automatically download any updated versions of the program from that location, after the code has been compiled and put in a JAR. Java Web Start also automates the process of creating Desktop and Start Menu shortcuts for your application. Java Web Start can also be very useful to programmers, since its easy deployment and automatic updating simplfy the debugging process. To use Java Web Start, do the following:

  1. Download Java Web Start. If you use Java Runtime Environment, v. 1.4.1 or higher You should already have Java Web Start. Note that the most recent version of Web Start is only available as part of the Java 1.4.1 JRE, and not as a separate download.

  2. Create a signed, executable JAR file of your application. Here are our barebones instructions for creating an executable JAR file and signing it.

  3. Create a JNLP (Java Network Launching Protocol) file. This is an XML file that provides Web Start with some basic information about the program to be executed. information about the JNLP syntax and the full technical specifications, but we'll provide a summary to get started quickly. The file name should end with the .jnlp suffix. Below is an example that shows the basic format. You can use the file sample.jnlp as a template, replacing the fields in all capitals with your own values.
    
    <?xml version="1.0" encoding="utf-8"?>  
    <!-- JNLP File for My Program v1.0 -->  
    <jnlp  
        spec="1.0+"  
        codebase="http://www.cs.princeton.edu/~myname/mydirectory"  
        href="myprogram.jnlp">  
        <information>  
            <title>My Program v1.0</title>  
            <vendor>CS Dept., Princeton University</vendor>  
            <homepage href="productpage.html"/> 
            <description>A program I wrote</description>
            <icon href="myicon.jpg">
            <offline-allowed/>  
        </information>  
        <security>  
            <all-permissions/>  
        </security>  
        <resources> 
            <j2se version="1.2+"/> 
            <jar href="myprogram.jar"/> 
        </resources>  
        <application-desc main-class="MyProgramMain">
            <argument>arg1</argument>
            <argument>arg2</argument>
        </application-desc>
    </jnlp>
    

    Explanation of the JNLP elements. The format is similar to HTML. Each piece of information is enclosed between two "tags" of the form <tag>...</tag>. Some attributes are placed in quotes within a tag. In addition, groups of elements are enclosed between tags with names like "information" and "resources".




  4. Finally, create a link to the JNLP file from a webpage. The HTML for this link will look like:
    <a href="myprogram.jnlp">Launch My Program</a>
    Just click the link, and the program should launch. The user running your program must also have Java Web Start.

Thomas P. Ventimiglia
Introduction to Computer Science
Last modified: Wed Jul 30 10:33:45 EDT 2003