Using SWT with Java Web Start on Mac OSX
Introduction
Developing rich-client applications has several usability advantages over
web applications, but many times recurring deployment costs inhibit us
from using rich-client applications in an enterprise environment where IT
is responsible for all software installations and upgrades. Java Web Start
provides an elegant way to automatically deploy and update rich-client
applications without the costs associated with traditional deployments. SWT
provides a great toolkit that makes Java applications appear very native and
enhance usability dramatically. However, because of a bug in the Mac OSX
implementation of SWT, you cannot launch SWT via the standard Java Web Start
client that comes packaged with the operating system. After looking around
for a solution to work around this bug, I've come up with the following. Note
that this approach is not ideal, but it will let you deploy SWT applications
using Java Web Start on Mac OSX.
Using a Different JNLP Client
The normal Web Start client that comes with OSX is a Swing based client, which
causes all sorts of problems when trying to launch SWT applications since those
applications are launched in the same process. In order to get around this, we
needed a Web Start launcher that did not contain a front end. To this end, we
employed OpenJNLP, an open implementation of the Java Web Start standard. We
were able to de-activate the Swing frontend and just use the client's dpwnloading,
caching, and launching facilities.
Bundling the Launcher Into a Nice Package
After writing a shell script to launch our SWT Web Start applications, we then
created a small application bundle that serves as the launcher. So, in order to
deploy this, the user just needs to download this application bundle once, and
when the bundle is run, it will download the application resources, launch the
application, and keep the resources up to date - all behind the scenes.
Here's a sample of our application bundle: jnlp_launcher.dmg
You will notice that this bundle is little more than a few OpenJNLP jars and a
shell script to launch the client. To set the URL of the Web Start repository that
you want to launch from, right-click on the bundle and choose "Show Package Contents".
Browse to the "Contents/MacOSX" folder. Inside you will find a file called "jnlplaunch".
This is the launcher shell script. Edit the script and insert your URL after JNLPURL=.
Save it and the launcher should be ready to use.
#!/bin/sh
JNLPURL=http://moria/jaguar/webstart/production/jaguar-macosx-moria.jnlp
BASEDIR=`dirname "$0"`
CP=../MacOS
cd "$BASEDIR/../WorkDir"
java \
-XstartOnFirstThread \
-classpath $CP/jnlp.jar:$CP/openjnlp-app.jar:$CP/openjnlp-lib.jar:$CP/openjnlp-extra.jar \
-Dorg.eclipse.swt.internal.carbon.noFocusRing \
-Dorg.eclipse.swt.internal.carbon.smallFonts \
org.nanode.jnlp.JNLPParser -internal $JNLPURL
Gotchas
There are several problems with this solution. First is that the OpenJNLP project seems to
be dying. At least they didn't return my e-mails and progess seems to have halted. However, their
code is still quite usable, but isn't terribly complete.
Also, the OpenJNLP client does not seem to implement extensions in the JNLP file. So, if you
are using those, you will have to rewrite the JNLP file without extensions.
Most of the time extensions are used to separate jar files that are signed by different authorities.
However, OpenJNLP does not implement any security measures, so signing jar files is not necessary and
therefore extensions do not need to be used for that.
The other major problem is that the user has no way of knowing what is happening when they launch
the launcher. It just bounces in the dock until all resources are downloaded and up to date.
Depending on the size of application and the network, this could take a while. An enhancement to
this shell script would be to pop up a dialog box explaining what is happening in the background.
Conclusion
All in all, this is definitely not a long-term solution. It would be much nicer to use the Web Start
client that comes with Mac OSX, but this will hopefully allow you to deploy SWT applications across
an enterprise environments without having to build and distribute application bundles for Mac OSX for each update.
Author
Written by Nathan Callender
Application Developer
November 9, 2005
Related Sources
OpenJNLP Home Page
Interested in implementing technology with SWT but need help?
Our consultants would be happy to help.
Contact us here.
|