Web Start Overview

Java's Comback On The Desktop

Gerald Bauer
JUG Austria Talk, January 2002


Table of Contents

Web Start Overview

Who is this guy?


Agenda - The Road Ahead


Is Java Dead On The Desktop? - What The Critics Say


Java On The Desktop: Dream On


Java On The Desktop: Good News


Why Java on the Desktop?


Isn't Dynamic HTML and JavaScript enough?


What's Wrong With Applets?


Five Years Later - Hello Web Start


Web Start vs. Applets

Web Start != Applet 2.0/NT


How Does It Work? The Magic Revealed


How Does It Work? One Click And You Are Off

Step 1: User clicks on hyperlink in browser (.jnlp)

Example: Web Page Snippet
Venus Application Publisher by Gerald Bauer

A user-friendly tool to help you package, sign and publish Java Network Launching Protocol (JNLP) apps.

Try Me More Info...


Hazel - JNLP to HTML converter by Gerald Bauer

Create Your Own JNLP App Catalogs. Hazel extracts all JNLP links from an HTML document and creates an informative, neat looking HTML document listing all JNLP applications.

Try Me More Info...


Example: Web Page HTML Source
<a href="http://www.jenomics.de/vamp/venus.jnlp">Try Me</a>

How Does It Work?

Step 2: Browser starts Helper App registered to handle .jnlp MIME type application/x-java-jnlp-file and hands over the user-clicked URL as argument

e.g. javaws[.exe] http://www.jenomics.de/vamp/venus.jnlp


How Does It Work? Start Me Up

Step 3: Web Start downloads all required Jars from Web Server

Download Vamp

How Does It Work? Voila, Bingo

Step 4: Web Start starts up App

Note: The App runs on its own Java Runtime outside the browser

Vamp In Action

Web Start In A Nutshell

Secure One-Click Startup From Any Browser, For Any Platform, From Anywhere.


Web Start, JNLP


How Can I Start A Web Start App?


What Is Desktop Integration?

Web Start Creates


JNLP File = XML Startup File

Example:

<jnlp href="venus.jnlp" codebase="http://www.jenomics.de/vamp">

  <information>
    <title>Venus Application Publisher</title>
    <vendor>Gerald Bauer</vendor>
    <homepage href="http://www.vamphq.com/"/>
    <description>A user-friendly tool to help you package, sign and publish Java Network Launching Protocol (JNLP) apps.</description>
    <icon href="venus.gif"/>
    <offline-allowed />
  </information>

  <security>
    <all-permissions />
  </security>

  <resources>
    <j2se version="1.4 1.3" />
    <jar href="lib/venus.jar" />
    <jar href="lib/luxor.jar" />
    <jar href="lib/bcel.jar" />
    <jar href="lib/kunststoff-1.11.jar" />
    <jar href="lib/velocity-1.1.jar" />
    ...
    <jar href="lib/log4j.jar" />
    <jar href="lib/skinlf-1.1.jar" />
    <jar href="lib/getopt108.jar" />
  </resources>

  <application-desc main-class="venus.Tool" />

</jnlp>

JNLP File Contents


JNLP Tags - Info about the App

Title

<title>Venus Application Publisher</title>
<title>Batik SVG Viewer</title>

Vendor

<vendor>Gerald Bauer</vendor>
<vendor>Apache Batik Project</vendor>

Icon

<icon href="venus.gif"/>
<icon href="smartcvs32x32.gif" width="64" height="64"/>

JNLP Tags - Links To Resources

Jars

<jar href="lib/venus.jar" />
<jar href="lib/luxor.jar" />
<jar href="lib/kunststoff-1.11.jar" />

Native Libs (aka DLLs, Shared Objects)

<nativelib href="lib/mousewheel.dll.jar" />

Properties

<property name="user.name" value="Zeus" />
<property name="luxor.debug.layout" value="true" />

Java Runtimes (aka JREs)

<j2se version="1.3" />
<j2se version="1.4 1.3 1.2.2+" />

JNLP Tags - Application Parameters

Main Class Only; No Arguments

<application-desc main-class="venus.Tool" />

Main Class Plus Arguments

<application-desc main-class="org.apache.batik.apps.svgbrowser.Main" >
  <argument>http://www.vamphq.com/>
</application-desc>

Alphabetical JNLP Tag List

<all-permissions> <icon> <package>
<applet-desc> <information> <param>
<application-desc> <installer-desc> <property>
<argument> <j2ee-application-client-permissions> <resources>
<component-desc> <j2se> <security>
<description> <jar> <title>
<ext-download> <jnlp> <vendor>
<extension> <nativelib>
<homepage> <offline-allowed>

JNLP Tag Overview

Tag Description
Root Tags
jnlp The jnlp file's one and only root .
Top Level Structural Tags
applet-desc [ param ] Describes how to startup a Java applet. Contains information about main class, parameters, size and more.
application-desc [ argument ] Describes how to startup a Java application. Contains information about the main class and arguments.
component-desc Specifies a component extension.
information Contains various descriptive information about the application such as title, vendor and homepage.
installer-desc Specifies an installer extension.
resources Contains an ordered set of resources that make up an application.
security Describes the application's security requirements.
Information Tags
description Describes the application in a single line, in a paragraph or in a couple of words for a tooltip.
homepage Contains a web address to the application's homepage.
icon Describes an icon/image for the application.
offline-allowed Indicates if the application can be started offline (that is, without a connection to the originating server).
vendor Contains the vendor's name.
title Contains the application's name.
Resources Tags
extension [ ext-download ] Describes a component or installer extension that is required to run the app.
j2se Describes a supported JRE version that the application can run on.
jar Describes a jar file.
nativelib Describes a jar containing native libraries (e.g. .dll, .so).
package Defines a relationship between a Java package or class name and a part.
property Describes a name/value pair that is available to the application as a system property.
Security Tags
all-permissions Indicates that the application needs full access to the local system and network.
j2ee-application-client-permissions Indicates that the application needs the set of permissions defined for J2EE client apps.

Web Start Builds On Proven Technology


What's New


What's In the JNLP Specification?

less than 80 pages; released December, 2000; JSR-56


Web Start Cache - End of Classpath Hell

URL + Version = Unique ID
  • Jars using the same URL are shared between apps and downloaded only once.
  • Jars using the same name but different URLs are kept separate.
Example:
http://www.vamphq.com/venus.jar
http://www.olympus.gr/godess/venus.jar


JNLP API - javax.jnlp

Usages


How To Deploy Your App?


Prepare Your App


Prepare Your Web Page

Web page contains standard HTML hyperlink. Example:

<a href="http://www.jenomics.de/vamp/venus.jnlp">Try Me</a>

<a href="skinlf/jnlp/demo.php">Start Skin L&F Demo</a>

Note: You can create JNLP files on-the-fly using scripts (PHP, Perl, Servlets, JSP, etc.). File endings (suffixes) don't have to be .jnlp, but can be .php or whatever. The browser uses the HTTP content-type header sent by the web server to know that it's a JNLP file that it needs to hand over to Web Start.


Prepare Your Web Server


Resource Loading - Rules To Live By

Rule 1: Java Archives only. No loose files. All your resources have to be packaged in Java Archives (jar) if you want to have them delivered to the user's machine and kept up-to-date automatically by Java Web Start.

Rule 2: No file paths. You can't use absolute or relative file paths to locate your jars holding your resources (e.g. c:/java/jws/.cache/resources.jar).

Absolute file paths won't work because you never know where Web Start will put your jar on the user's machine.

Relative file paths won't work because Java Web Start mangles the names of your jars (e.g. venus.jar becomes RMvenus.jar) and every JNLP client has the right to mangle your names in a different way and you, therefore, can't predict the name with which your jar will be rechristend and end up on the user's machine in the app cache.

Conclusion: The only option left is using ClassLoader.getResource() or ClassLoader.getResourceAsStream() to get resources (icons, html files, property files, etc.) out of your jars.


Resource Anchor Trick Revealed

Create an empty class (aka resource anchor) and package it with your resources. Example:

public class ResourceAnchor
{
    public ResourceAnchor()
    {
    }
}

The ResourceAnchor class only purpose is to identify the Jar holding your resources. (No need to burn the weather report on your toast in the constructor.)

Example: Content of Jar that holds ResourceAnchor.class and all resources such as menu.properties, world2.gif, etc.

vamp/tutorial/CmdShowUrl.class
vamp/tutorial/HelloVenus$1.class
vamp/tutorial/HelloVenus.class
vamp/tutorial/Main.class
vamp/tutorial/menu.properties
vamp/tutorial/ResourceAnchor.class
vamp/tutorial/WebBrowser.class
vamp/tutorial/images/inform.gif
vamp/tutorial/images/world2.gif


Resource Anchor Trick Continued - Drill For Images In Jars

To retrieve your resources you need to get a hand on a class loader. Here's the pick-up line:

ClassLoader cl = ResourceAnchor.class.getClassLoader();

To get an icon from a Jar use ClassLoader.getResource(). Example:

URL worldIconUrl = cl.getResource( "vamp/tutorial/images/world2.gif" );
ImageIcon worldIcon = new ImageIcon( worldIconUrl );

Or in compressed form:

ImageIcon worldIcon = new ImageIcon( cl.getResource( "vamp/tutorial/images/world2.gif" ) );

Tip: Use only lower case resource names as on some machines retrieving resources with both upper and lower case letters will fail (e.g rename World2.gif to world2.gif).


Resource Anchor Trick Continued - How About Property Files?

To get menu.properties out of the jar use ClassLoader.getResourceAsStream(). Example:

Properties props = new Properties();
try
{
  props.load( cl.getResourceAsStream( "vamp/tutorial/menu.properties"  ));
}
catch( IOException ioex )
{
  System.err.println( "*** failed to load properties: " + ioex.toString() );
}

Advanced Resource Loading - Rachel Open-Source Resource Loading Toolkit


Use class:// protcol handler

Use the syntax below to create a class:// protocol URL:

class://<class>/<path>

Examples:

class://venus.Tool/images/powered-by-velocity.gif
class://Chrome/skinlf/themes/aqua.zip
class://JavaDocAnchor/javadoc/index.html
class://ThemeAnchor/images/world2.gif

Benefits:

Get resource using java.net.URL. Example:

URL appIconUrl = new URL( "class://ThemeAnchor/images/inform.gif" );
ImageIcon appIcon =  new ImageIcon( appIconUrl );

or

URL themepack = new URL( "class://ThemeAnchor/skinlf/themes/modern.zip" );
Skin skin = SkinLookAndFeel.loadThemePack( themepack );

Prepare Your Web Server - Apache .htaccess Tip

If your provider runs Apache (as many do) and hasn't switched off support for the .htaccess feature (which is usually true) there's an easier way to add the JNLP MIME type. Add the two lines below to the .htaccess file at the top directory of your site (or create one, if it doesn't exit):

AddType application/x-java-jnlp-file    .jnlp
AddType application/x-java-archive-diff .jardiff

Now try to load a JNLP file from your site. If you browser still displays the content of the JNLP file instead of starting Web Start, shift-click the Reload button to make sure no caches are involved (this is at least how it works for Netscape).


Prepare Your Web Server - PHP Header Tip

Use scripts such as PHP or Perl to set the MIME type header dynamically. In PHP this is a one line affair.


<? header ("Content-Type: application/x-java-jnlp-file"); ?>
<jnlp codebase="http://www.L2FProd.com/software/skinlf/jnlp"
      href="demo.php">
  <information>
    <title>Skin LF Java Web Start Demo</title>
    <vendor>L2FProd.com</vendor>
    <homepage href="http://www.L2FProd.com/software/skinlf/" />
    <description>Skin LF Java Web Start Demo</description>
    <offline-allowed />
  </information>
  <resources>
    <j2se version="1.4+ 1.3+"/>
    <jar href="demo.jar"/>
    <extension name="Skin Look And Feel" href="skinlf.php"/>
  </resources>
  <application-desc main-class="javawebstart">
  </application-desc>
</jnlp>

Advanced Web Start Topics


Package Web Start App In Web Archive (.war)

Example:

/install.html
/venus.jnlp
/venus.gif
/lib/venus.jar
/lib/luxor.jar
/lib/bcel.jar
/lib/kunststoff-1.11.jar
/lib/velocity-1.1.jar
... more jars
/lib/log4j.jar
/lib/skinlf-1.1.jar
/lib/getopt108.jar
/WEB-INF/web.xml
/WEB-INF/lib/jnlp-servlet.jar
/WEB-INF/lib/jaxp.jar
/WEB-INF/lib/parser.jar

Add JnlpDownloadServlet (jnlp-servlet.jar) to Web Archive (.war)

Benefits:


More Benefits

Sun's JnlpDownloadServlet


Loading On Demand Example


Loading On Demand Example - JNLP Files

Main JNLP File: webpad.jnlp

<resources>

  <jar href="webpad.jar"/>
  <jar href="jlfgr.jar"/>
  <jar href="holidays.jar" download="lazy" part="help" />
  <extension href="javahelp.jnlp">
    <ext-download ext-part="javahelp" download="lazy" part="help"/>
  </extension>

</resources>

Help JNLP File: javahelp.jnlp

<jnlp codebase="$$codebase">
  <information>
    <title>Hava Help</title>
    <vendor>Sun Microsystems</vendor>
  </information>

  <resources>
    <jar href="jhcore.jar">
    <jar href="jh.jar" part="javahelp" download="lazy">
  </resources>

  <component-desc/>
</jnlp>

Loading On Demand Example - DownloadService API


Incremental Update/Jar Diffs


Jar Diff Format (=Delta Between Two Versions)

Example: Jar Diff Jar

META-INF/INDEX.JD
com/mysite/app/Main.class
com/mysite/app/Window2.class

Example: Contents of INDEX.JD

version 1.0
remove com/mysite/app/QuickHack.class
move com/mysite/app/stuff.properties com/mysite/app/app.properties

Offline/CD Installation Options


What Is A Client Archive (.car)?

Client archives (.car) are standard jars that include all required jars, icons as well as a all required JNLP descriptors including extensions that are needed by an app in a single jar similar to RPM packages.

Example: Contents of pam.car client archive

Client Archive Example

Client archives can be browsed and installed from CDs, for example, using package managers.

Example: Pam - Vamp Package Manager In Action

Pam - Vamp Package Manager

Open-Source JNLP Clients (aka Web Start Clones)

OpenJNLP About Popup

Other Open-Source JNLP Projects


Venus Application Publisher (Vamp) Tools for JNLP/Web Start


Web Start 2.0 - If I Were King

Cache API - Let multiple JNLP Clients peacefully coexist

The Web Start Cache is the holy grail of Web Start everyone will try to get a hand on as it has great potential to lock you in so that you can be milked for money. What user would give up all her apps in the cache just for trying out a different Web Start brand? Just daring souls, I guess.

Multiple JNLP clients (aka Java Web Start brands) should be able to peacefully coexist. The miracle could be achieved through a mandatory Cache API that gives you full read and write access to the cache.

Using a Cache API, for example, would make it fairly easy to create a tool that upgrades all apps in the cache at once. The tool could be scheduled to upgrade all apps on the user's behalf daily after midnight without supervision on a locked-down desktop, for example. This method would be superior to what some vendors propose today. They would rather prefer to let users watch the real-time, live upgrade in a cermony in the morning with everyone else upgrading at the same time so that they can charge you $25,000 per application for a clustering server that breaks down under the workload anyway and if you complain you will be told that it's time to buy a closed-source JNLP client that supports checkpointing, bandwith throttling and more for just $300 per seat.

Make The Command Line Work

If you type javaws -help or javaws -? nothing will be revealed. Web Start evidently doesn't have any command line options yet, but it should.


Web Start 2.0 - Looking In The Cristal Ball

Some features under consideration include:

You can request or vote for new Web Start features at Sun's Bug Parade at http://www.vamphq.com/.


Web Start App Directories - Where Do I Find Web Start Apps

Check out the following indices that list JNLP/Web Start apps:


Up2Go.Net - Web Start App Examples


Resources/Links

Web Start/JNLP

FAQs - Answers, Answers, Answers

Developer links that include code examples:


Books with major Web Start content

Java Deployment (JNLP, WebStart, J2EE, J2SE) by Mauro Marinilli, September 2001, 512 pages, paper format, ISBN: 0-672-32182-3, Sams Publishing

Chapter 2: An Abstract Model for Deployment and Chapter 11: Runtime Client Services of Mauro Marinilli's Java Deployment with JNLP and Web Start book are online for free at Sun's Java Developer Connection (JDC) site at http://www.vamphq.com/

Early Adopter: J2SE 1.4 by James Hart, September 2001, 200pp, Wrox Press

In Chapter 3: Clients James Hart explains JNLP and Web Start and develops a Web Start example app for viewing photographs in a sandboxed and in a signed version.


That's it - The Future Just Happened

Visit http://www.vamphq.com/ for more info