Java Web Start makes deploying and updating Java applications quick and easy. However, to take advantage of Web Start, users must already have a Java Virtual Machine (JVM) with the Web Start application installed. Some operating system vendors, such as Apple, install these components by default. Unfortunately, Apple is in the minority, as most operating systems do not come with Web Start preinstalled.
Check out the previous installments
Part one introduced Web Start and explained how to prepare an application for Web Start deployment. Part two showed how to expand the rights of an application running within the Web Start security sandbox.
Luckily, getting a JVM and Web Start has gotten much easier with the release of the Java Plug-in from Sun. The Java Plug-in allows Web browsers to fetch JVM to allow the execution of Java applets embedded in Web pages. The Java Plug-in makes writing Java applets more practical because applet developers are no longer stuck with the low quality JVMs bundled with the user’s browser—if any was bundled at all. The Java Plug-in also provides a great benefit to developers deploying applications through Web Start, which we’ll discuss later.
Installation of the Java Plug-in through an Internet Explorer user’s browser is quite simple. Just include HTML as found in Listing A to prompt the user to download and install the plug-in. The object tag in this HTML snippet tells the browser that if it has not already done so, it should download the Java 1.4.1 Virtual Machine installer. The browser automatically runs the installer, which steps the user through the simple click-for-next JVM installation process. (We’ll look at the Redirect.class and mine.jnlp entries in that snippet shortly.)
To the great benefit of developers using Web Start, the JVM downloaded in this fashion is not only available to the Web browser, but also is fully available to all of the system. This means that a painless browser-based procedure can be used to install software that will be used outside the browser. Even better is the fact that Java 1.4 Virtual Machines come bundled with Java Web Start. Thus, that HTML snippet, which the browser fetched to handle applets, has provided everything the user needs to run Web Start deployed applications.
Invoking the JNLP file
The next task is to automatically invoke the JNLP file for the desired application after the successful installation of the JVM and Web Start. This is handled by a simple Java applet that prompts the browser to open a specified URL. Listing B contains the source code for just such an applet. A quick look shows that the applet queries one parameter, named target, to which it sends the browser.
The invocation of the redirector applet and the specification of the target URL are both contained in the object tag in Listing A. The code parameter gives the name of the applet to be executed once JVM installation is complete. The target parameter provides the URL to which the redirector applet will send the user’s browser. In the example in Listing A, notice that the Redirect applet, whose source is provided in Listing B, is to be invoked after installation. The Redirect applet will then send the user’s browser to a file named mine.jnlp relative to the location of the HTML file in which the object tag is found.
After the installation of the JVM and Web Start, the user’s browser will consider JNLP files to be handled by the Web Start application. This execution of Web Start will launch the application, resulting in the fetching and execution of the Web Start deployed application.
It should be noted that if the user already has a 1.4.1 JVM installed, the browser will not fetch and install one a second time. On successive runs, the applet launches straight away and does its redirection immediately.
The multistage nature of this HTML to Plug-in to applet to Web Start to application installation progression may seem a tad convoluted from the developer’s point of view, but to an end user it’s quick, seamless, and easy—exactly how you want it to be.
Another cup of Joe
What types of Java articles do you want to see? Tell us or post a comment below.