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:
-
Click on a jnlp URL href link in your browser like
this:
-
type
javaws http://mindprod.com/webstart/esper.jnlp
to install without a browser.
-
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:
-
rich clients
-
rich Internet apps
-
rich desktop apps
-
weblets, though Gerald Bauer, a Java Web Start developer, told me this term was
not correct, because it improperly implied that the applications were
necessarily small.
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:
-
J:\j2sdk1.4.2_04\jre\javaws\Java
Web Start 1.2.0_03
-
J:\j2sdk1.4.2_04\jre\javaws\
-
C:\Program Files\Java\j2re1.4.2_04\javaws
-
C:\Program Files\Java Web Start
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:
-
It avoids making the user wait to do useful work. Most of the time the update is
not critical.
-
It only bothers refreshing programs you actually are actively using.
-
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
-
Java Web Start is the easiest to use installer both for developer and client.
-
Clients can try out new apps with just a single click.
-
Java Web Start automatically applies updates.
-
Initial downloads are compact.
-
Java Web Start puts almost no restrictions on how you code your application. You
can add it later, and take it off later without affecting anything else.
What's Wrong With Java Web Start
-
Java Web Start applications are painfully slow to start. The monitor loads a
fresh JVM for itself and for each application. Applications always check on the
web for updates, downloading and processing an entire new JNLP file, rather than
just checking its date.
-
Updates take just about as long to download as the original application. There
has been almost no cleverness applied to make the updates compact.
-
It requires custom code running on the ISP to properly serve the jardiff
files or to use the coming pack200 hyper compression.
-
It has not changed much since its initial release. It may be yet another
orphaned product. It does not deserve to be. However, Sun has released a new
beta 1.2 after a year or so of nothing happening, and it has been integrated
into the JRE, so we'll see if it is picking up steam again. Even if it is
orphaned nothing to terrible will happen. Unless you write unsigned JWS apps and
use the JWS sandbox, your JWS apps will run fine standalone.
-
It requires special configuring of the JNLP MIME type both at the ISP and in the
client's browser. Neither of these are under the developer's direct control.
-
If you have an urgent update, you can't force it to be installed before the app
is ever run again.
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
-
If Java Web Start behaves strangely, try killing any javaw.exe,
java.exe and javaws.exe
tasks.
-
If that does not work, try rebooting.
-
If that does not work try uninstalling and reinstalling the faulty app.
-
If that does not work, try clearing the cache with File |
Preferences | Advanced | Clear Folder. This will uninstall all your apps.
Then reinstall.
-
If that does not work go into C:\Documents And Settings\Administrator\Application
Data\Sun\Java\Deployment\ and delete files associated with the
recalcitrant application.
-
If that does not work go into C:\Documents And Settings\Administrator\Data
and delete files associated with the recalcitrant application.
-
If that does not work, uninstall the JRE and reinstall it.
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.
-
Clio: single-jar installer (app
served up through built-in web server)
-
Jess: single-jar installer (app
installed directly into Web Start cache)
-
Celia: command line installer to
install web archives (
.war) or client archives (.car)
directly into Web Start cache
-
Pam - package manager that
installs web archives (
.war) or client archives (.car)
directly into Web Start cache
-
Nullsoft Installer plus Celia:
(Windows Only) - single Windows (
.exe) that installs app directly
into Web Start cache
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:
-
Clients don't have to download the app every time, only when it changes.
-
Updates to the application are automatic.
-
You don't get variable behaviour caused by bugs and obsolete software installed
in various browsers.
-
There is more free RAM without the browser there too.
-
Java Web Start automatically checks for version compatibility.