Java Glossary : Java Web Start

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : J words : Java Web Start.

logoJava Web Start
Sun's tool for installing Java apps and updates. Note it is called Web Start , two words, not WebStart . Don't confuse Java Web Start with Solaris Web Start which is an installer for Solaris platform-specific software. It makes it easy for users to install Java apps once they have a web start enabled browser, or the web start app installed.

There are three ways to install a Java Web Start Application:

  1. Click on a jnlp URL href link in your browser like this:
  2. type

    javaws http://mindprod.com/webstart/esper.jnlp
    

    to install without a browser.

  3. Start Java Web Start, i.e. javaws.exe, then type or paste in the name of a jnlp reference such as http://mindprod.com/webstart/esper.jnlp into the locate box.
From then on updates are automatic. For the browser link to work, both the ISP and the browser must have JNLP MIME types configured properly, and the browser must associate JNLP files with Java Web Start.

Opera and Java Web Start

To run Java Web Start with the Opera browser, you need to set up an association between MIME type application/x-java-jnlp-file, file extension jnlp, and application C:\Program Files\Java\j2re1.4.2_04\javaws\javaws.exe. You do this is the Preferences | file types section.

What Is a Java Web Start Application?

Java web start applications don't require a browser to run, though they can be triggered from a browser. They don't require an Internet connection to run, though normally would require one to download. Unlike Applets, all application jars are cached on the client and are never automatically discarded. They are a quite different sort of animal from Applets, and are more closely allied to applications. Since they are only downloaded once, they can be just as large as any other Java application, e.g. running from a few K to 25 megabytes. I think of them as a Java application plus a simple installer and automatic update applier. The entire installation is controlled by a short XML text file with the extension *.jnlp.

Some of the terms for Java web Start applications are:

Web Resources

Gotchas

Starting with JDK 1.4.2, Java Web Start gets installed many times. This provides potential for using out of date copies. Here are places I have seen it install:

Contrary to the documentation, the class files you need, e.g. javax.jnlp.*, com.sun.javaws.* and com.sun.jnlp.* live in C:\Program Files\Java\j2re1.4.2_04\javaws\javaws.jar in the JRE and in J:\j2sdk1.4.2_04\jre\javaws\javasws.jar in the JDK. This file is automatically installed when you install the JRE or JDK. You will need the javaws.jar on your classpath if you develop (i.e. compile) JWS applications, but not if you merely run them. Copy javaws.jar to the ext directories.

The Web Start install does not tweak the Opera browser to understand jnlp files. You must do that manually with File | Preferences | File Types | New . The extension is .jnlp ; the MIME type is application/x-java-jnlp-file ; the open with other application is program files\Java Web Start\javaws.exe.

If you are a developer broadcasting JWS programs, you must also talk to the ISP who hosts your website to set up association from extension to MIME type for .jnlp and any of the other Java file types you use such as .class, .java, .jar, .jardiff and .ser . See MIME for details.

Web Start transfers only jar files. It is up to the application to unpack them if necessary. However, there is the nativelib tag that lets you specify a jar full of dlls for JNI native code that it will unpack automatically. Java Web Start does not deal well with updating large files. If so much as one comma in them changes, it transfers the entire file. It does have a feature called jardiffs for sending a jar file of only members that have changed. It needs some automation to make it more practical to use. See the Automatic File Update and Delta Creator student project for a solution to these problems.

jNLP

JNLP (Java Network Launching Protocol) is the specification. You create an XML specification file, e.g. esper.jnlp that looks like this:
<?xml version="1.0" encoding="utf-8"?>

<jnlp spec="1.0+" codebase="http://www.mindprod.com/webstart" href="esper.jnlp">

<information>
<title>Esperanta Tradukilo Vortope 1.9</title>

<vendor>Canadian Mind Products</vendor>
<homepage href="http://www.mindprod.com/" />

<description>Word for word Esperanto to/from English translator.</description>
<description kind="short">Looks up words on local and Internet Esperanto dictionaries.</description>
<description kind="tooltip">Tradukilo</description>
<!-- gif or jpg only, transparency does not work. -->
<icon href="http://www.mindprod.com/images/greenstar64x64.gif" width="64" height="64" />
<offline-allowed/>

</information>

<resources>

<!-- Acceptable JVMs in preferred order, best first -->
<j2se version="1.4.2_04" href="http://java.sun.com/products/autodl/j2se" initial-heap-size="128m" max-heap-size="512m" />
<j2se version="1.4.2_03" href="http://java.sun.com/products/autodl/j2se" />
<j2se version="1.4.2_02" href="http://java.sun.com/products/autodl/j2se" />
<j2se version="1.4.2_01" href="http://java.sun.com/products/autodl/j2se" />
<j2se version="1.4.2" href="http://java.sun.com/products/autodl/j2se" />

<!-- application code -->
<jar href="esper.jar" />

<!-- data dictionaries in compressed form -->
<jar href="dicts.jar" />
<!-- set a -D system property -->
<property name="flavour" value="strawberry" />

</resources>

<!-- JNI native .so code -->
<resources os="SunOS" arch="sparc">
<nativelib href="lib/solaris/corelibs.jar"/>
</resources>

<!-- JNI native .dll code -->
<resources os="Windows" arch="x86">
<nativelib href="lib/windows/corelibs.jar"/>
</resources>

<security>

<all-permissions />
</security>

<!-- application class with main method -->
<application-desc main-class="com.mindprod.esper.Esperanto" />

<!-- code run once on install to unpack dicts.jar -->
<installer-desc main-class="com.mindprod.esper.Installer" />

</jnlp>

If the app needs to be online to execute, remove the <offline-allowed/> from the information section. Beware, some websites erroneously document the parameter as allow-offline.

<j2se version="1.3+" /> Does not mean that JDK version 1.3 or higher will be just fine. Read the specs carefully. JWS will automatically download and install any needed JREs.

Features

For people who have dial-up Internet connections, JWS is clever. If there is a dial-up connection in progress, it checks for updates, and downloads them if necessary. If there is no connection, is does not dial. It simply uses the old code.

There are a number of services your Web Start application can use. DownloadService lets you check what is in the cache, and remove items from the cache. FileSaveService lets even unsigned applications write to hard disk.

Web Start has features for keeping track of various versions of files and automatically ensuring the users have the most up-to-date files. Unfortunately, the version-based protocol requires special support on the Web server. This support can be provided using servlets, CGI-scripts, or by similar means. You can't pull it off simply by changing the names of the various jar files you upload to a standard http server. Without a special server, files are downloaded with ordinary HTTP with is not restartable if the download aborts. Sun provides a reference Servlet in the download that implements the JNLP protocol that you could run your server. I have no experience with it.

Web Start has a sandbox and a signing mechanism very similar to that used by Applets. However, it provides constrained ability to read and write files without signing.

Web Start is Sun's specific implementation of JNLP. There are other JNLP projects: the Sitraka Deploy Director, Juniper and OpenJNLP on SourceForge, Java URL by Tal Liron. Fontanus Zydego has an implementation similar to JNLP.

I am not sure which of the above projects are client/server or both.

JNLP leaves this unspecified, but Sun's Java Web Start reference implementation downloads and applies any updates only after you run a program. This unexpected convention has three advantages:

  1. It avoids making the user wait to do useful work. Most of the time the update is not critical.
  2. It only bothers refreshing programs you actually are actively using.
  3. It does not require unattended access to the Internet to fetch downloads, which would happen if updates were scheduled each evening on all apps, LiveUpdate style.

The disadvantage is if a customer complains about a bug and you fix it, they won't see the fix the next time they run the program, only the time after that.

The nice thing about Java Web Start is that it does not put many restrictions on how you code. It is very easy to take and ordinary app or Applet and tack on a little bit to make it ready for Java Web Start. You don't need two have different code bases, one for standalone and one for JWS. This also protects you in case some day JWS goes the way of all flesh. You could then easily convert your JWS back to pure standalone.

Debugging

If you type javaws and launch your app, there is a preferences section where you can turn on a java console and console logging to a file. You need the file because the console disappears the instant the app terminates.

Alway have your app display the version, and change the version for every compile. Otherwise, you could very easily be debugging an old version in cache and not know it. Redating the JNLP files seems to help flush caches faster.

Check the list of running tasks. Sometimes you will see failed java incarnations hanging on. They need to be manually killed or you need to reboot to get rid of them. They can interfere with your debugging.

Especially during launch failure, check all the tabs of the dialog box for clues to the problem. There is much more information than first meets the eye in the general tab.

Where are the Files?

Java Web Start hides your jar files away in a directory with an unwieldy name like: C:\Documents and Settings\Administrator\Application Data\Sun\Java\Deployment\javaws\cache\http\Dwww.songprojector.com\P80\DM~roedy\DMwebstart or C:\Documents and Settings\Administrator\Application Data\Sun\Java\Deployment\javaws\cache\http\Dwww.mindprod.com\P80. This ponderous scheme helps avoid name collisions from different websites, even if they deploy the same application. JWS renames the files; e.g. cyberview.jar becomes RMcyberview.jar to make them harder to find. It also creates the camouflaging RCCyberview.jar for the corresponding certificate, and RTCyberview.jar for some history of your used of the jar. If your Java WebStart application creates any files, they will go into a random directory, whatever happened to be the current directory at the time the program was launched.

You can pass configuring information to your application two ways via the resources/properties section of the JNLP file and by putting information in the jars to be got at with getResource.

Persistence

The Java Webstart java.util.prefs.Preferences on Windows uses the registry to store persistent configuration information for your applications. Check the registry My Computer/HKEY_CURRENT_USER/Software/JavaSoft/Prefs for the entries.

Unsigned applications have to use the Mickey Mouse PersistenceService APIs. Signed applications could use the registry-based Preferences class.

Why not just use regular files that way any sane programmer would? The problem is finding them again the next time you execute. There is no data directory naturally associated with the application. Unless you put them in an absolute location, you at least need some way of recalling the name of the directory where all the data are.

Detecting Java Web Start

You can use JavaScript to detect whether a browser has been configured to understand the JNLP mime type, which is the usual barrier to running JWS applications.
Here is the Javascript code you need to generate the above display:

<script language="javascript" type="text/javascript">
<!--
if ( navigator.mimeTypes
&& navigator.mimeTypes.length
&& navigator.mimeTypes[ 'application/x-java-jnlp-file' ] )
document.write( "Your browser appears to be already configured properly for Java Web Start." );
else
document.write( "Your browser is not configured properly for Java Web Start *.jnlp and application/x-java-jnlp-file MIME types." );
// -->
</script>

You can test your Java Web Start installation with some of Sun's little Web Start Applications.

What's Right With Java Web Start

What's Wrong With Java Web Start

New Features

In the coming JWS version, you will be able to build associations from file extensions with your JNLP file. You can set up open and print associations. There are various features for security and controlling security settings.

There is still no way for a JWS app to find some persistent disk space in an easy way. It pretty well has to ask the user for the name of some directory to use.

Recovering From Java Web Start Failures

Distributing Java WebStart Apps on CD

I have not yet quite got this working, though I am close. The problem is the codebase parameter in the JNLP file must be absolute and match its actual location. In other words, if the CD is in drive R: then the codebase in the JNLP file must be file://localhost/R:/. If it is drive W: then the JNLP file must contain a codebase parameter file://localhost/W:/. My solution was to automatically generate 26 variants on the JNLP file and put them all on the CD. The user could then wake up Java Web Start and feed it the appropriate URL matching their CD ROM drive letter. This is a bit confusing for the user, so I wrote a little Windows-only C program to figure out the drive letter and then select the correct JNLP file. It can't simply generate a custom JNLP file on the fly since the result has to be on the unwriteable CD along with the jar. The problem was, my program did not know where javaws.exe was installed so it could not automatically start it up. Javaws.exe does not put itself on the path, and does not put any kicker to itself on the path the way it does for java.exe. So I had to spawn a command processor that understood the *.jnlp extension. This is command.com for Win98 and cmd.exe for Windows 2000. I then added an autorun.inf to kick the whole process off automatically. The main problem with this approach other than that it requires 26 generated JNLP files, is that it works only on Windows. Here is the C++ source code for Setup.exe.

Others have tried more sophisticated approaches. The Vamp ( Venus Application Publisher) people have come up with a number of ingenious Rube Goldberg solutions. It is not their fault. Sun has made this needlessly difficult.

The proper solution to the CD install problem is for Sun to support codebase="cd". It has to be possible for Apps to redistribute themselves in the field on CD to get past firewalls, and carrying data with them. End users can't tolerate complicated procedures just to move the app to CD. What Sun plans to do instead is this:

javaws -import -codebase file:///R:/appa R:/appa/jnlp/app.jnlp

to allow you to override the codebase on the command line. This is not user friendly for manually typing, and further it is not something a setup.exe program can launch because it does not know where javaws.exe is. It is not on the path. Perhaps if they put it on the path using a dummy kicker similar to java.exe this kludge will work.

Passwords

You can protect a JNLP file from public access by putting the link and jnlp file in a password-protected directory. If you can't get a browser to access it, you can access it directly from Java Web Start by keying in an url that embeds the userid and password like this where roedy is your userid and sesame is your password.
http://roedy:sesame@mindprod.com/replicator/replicatorreceiverwebsite.jnlp

Summary

I like Java Web Start for the following reasons:


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 7373.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/javawebstart.html J:\mindprod\jgloss\javawebstart.html