Trail: Deployment
Lesson: Java Web Start
Deploying a Java Web Start Application
Home Page > Deployment > Java Web Start

Deploying a Java Web Start Application

To deploy your Java Web Start application, first compile the source code and package it as a JAR file.

Java Web Start applications are launched by using the Java Network Launch Protocol (JNLP). Hence, you must create a JNLP file to deploy your application.

The Deployment Toolkit script contains useful JavaScript functions that can be used to deploy Java Web Start applications on a web page.

If you are unfamiliar with these deployment technologies, review the Deployment In-Depth lesson before proceeding.

Here are some step-by-step instructions to package and deploy your application. The Dynamic Tree Demo application is used to illustrate the deployment of Java Web Start applications. You might want to set up build scripts to execute some of the following steps.

Click the following Launch button to launch the Dynamic Tree Demo application.


Note:  

If you don't see the Java Web Start application running, make sure that you have at least the Java 2 Platform, Standard Edition (J2SE) 1.4.2 release on your client. If not, download and install the latest release of the Java SE Development Kit (JDK).



Note:  

If you don't see the example running, you might need to enable the JavaScript interpreter in your browser so that the Deployment Toolkit script can function properly.


  1. Compile your application's Java code and make sure that all class files and resources such as images are in a separate directory.

    In the Dynamic Tree Demo application, the compiled classes are placed in the build/classes/webstartComponentArch directory.

  2. Create a JAR file containing your application's class files and resources.

    For example, the following command creates a JAR file with the class files in the build/classes/webstartComponentArch directory.

        cd build/classes
        jar cvf  DynamicTreeDemo.jar  webstartComponentArch
    
    See the Packaging Programs in JAR Files lesson to learn more about creating and using JAR files.
  3. Create a JNLP file that describes how your application should be launched.

    Here is the JNLP file that is used to launch the Dynamic Tree Demo application. The source for dynamictree-webstart.jnlp follows:

        
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" 
        codebase="http://docs.oracle.com/javase/tutorialJWS/deployment/webstart/ex6/webstart_ComponentArch_DynamicTreeDemo" 
        href="dynamictree-webstart.jnlp">
        <information>
            <title>Dynamic Tree Demo</title>
            <vendor>Dynamic Team</vendor>
        </information>
        <resources>
            <!-- Application Resources -->
            <j2se version="1.6+"
                  href="http://java.sun.com/products/autodl/j2se"/>
            <jar href="DynamicTreeDemo.jar" main="true" />
    
        </resources>
        <application-desc
             name="Dynamic Tree Demo Application"
             main-class="webstartComponentArch.DynamicTreeApplication"
             width="300"
             height="300">
         </application-desc>
         <update check="background"/>
    </jnlp>                                   
    
    Structure of the JNLP File describes the JNLP file syntax and options.

    Note: The codebase and href attributes are optional when deploying Java Web Start applications that will run on at least the Java SE 6 update 18 release or later. You must specify the codebase and href attributes when deploying Java Web Start applications that will run with previous releases of the Java Runtime Environment software.
  4. Create the HTML page from which your application will be launched. Invoke Deployment Toolkit functions to deploy the Java Web Start application.

    In the example, the Dynamic Tree Demo application is deployed in JavaWebStartAppPage.html.

    <body>
        ....
        <script src="http://www.java.com/js/deployJava.js"></script>
        <script>
            // using JavaScript to get location of JNLP file relative to HTML page
            var dir = location.href.substring(0, location.href.lastIndexOf('/')+1);
            var url = dir + "dynamictree-webstart.jnlp";
            deployJava.createWebStartLaunchButton(url, '1.6.0');
        </script>
        ....
    </body>
    

    If you are not sure whether your end users will have the JavaScript interpreter enabled in their browsers, you can deploy the Java Web Start application directly by creating a link to the JNLP file as follows:

    <a href="/absolute path to JNLP file/dynamictree-webstart.jnlp">Launch Notepad Application</a>
    

    If you deploy the Java Web Start application with a direct link, you cannot take advantage of the additional checks that the Deployment Toolkit functions provide. See Deploying a Java Web Start Application in the Deployment In-Depth lesson for details.

  5. Place the application's JAR file, JNLP file, and HTML page in the appropriate folders.

    For this example, place DynamicTreeDemo.jar, dynamictree-webstart.jnlp, and JavaWebStartAppPage.html in the same directory on the local machine or a web server. A web server is not required to test the Java Web Start application.

  6. Open the application's HTML page in a browser to view the application. Check the Java Console log for error and debugging messages.

Download source code for the Dynamic Tree Demo example to experiment further.


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: Retrieving Resources
Next page: Setting Up a Web Server