SWT Tips and Tricks: Part 2 - Using Java Web Start with SWT: A Win-Win Solution
Introduction
SWT is a growing Java GUI toolkit that is making inroads into commercial
and corporate development because of its cross-platform interface to
the operating system's native GUI toolkits. In many cases, users love the
fact that it looks and feels native, and uses widgets that they are familiar with.
However, deploying SWT applications across an enterprise environment can
be tricky and tedious if not done correctly. Using Java WebStart can bring
these great looking applications to the desktop while eliminating manual
deployment and updates for the IT department and/or end users.
Deployment Goals with Java Web Start
When releasing commercial software to the general public, it is satisfactory to build
an installer for each release and have the end user install or upgrade each
machince manually. However, the rules change considerably when one enters the
corporate and enterprise worlds.
End users are not expected to upgrade their own software,
and often are prohibited from doing so. They just want the latest and greatest without
doing anything - and that's perfectly fine. In this environment, as business strategies
change, so does technology, and this make updates much more frequent. So, developers want
to get their updates out quickly, without building installers and packaging up their into
nice, neat bundles. Finally, systems administrators would rather not have anything to do with
the process of each update. Plus, they want a solutions that is robust, standards compliant and
simple to implement. The rule of thumb here is to create a deployment
procedure that is:
- Seemless to the end user
- As simple and as fast as possible for developers
- Highly reliable and fault tolerant
For these reasons, many enterprise environments have become completely web-based. However,
using Java Web Start, you can create a deployment procedure that meets each one of these
goals and still deliver a rich client to end users without any more work.
Getting Started
1. Create the Native Library Jar File
First, Java Web Start requires that all files of the application be packaged up
into Jar files. Since SWT uses native libraries, these need to get packaged as
well. You will need to make a package for each operating system that you want
to support. So, for Windows, download the SWT libraries. Save the swt.jar file
for later, and just zip the *.dll files together into the root of a zip file, and
rename it to have a *.jar extension. On the Mac platform, they are *.jnilib files
and on Linux they are *.so files.
2. Sign the Jar Files
Once you have created the native library Jar file, gather the rest of the Jar files
that your application uses. Do not forget to include the Jar files that came
with SWT for the platforms that you want to support. Since SWT uses native JNI
calls to access the native libraries, Java Web Start requires that all Jar files
for an application be signed by the same certificate. Therefore, let's create a
self-signed certificate. For information about using certificates signed by a
certifcate authority, visit the Java keystore utility man pages.
If you do not know how to sign Jar files, follow these instructions:
http://java.sun.com/docs/books/tutorial/jar/sign/signing.html
3. Create the Jar Archive
Java Web Start requires that all the Jar files of an application be located on a
web server. (However, you can also use a Windows file share with Java Web Start).
So, create a directory on the web server of your choice. Make sure that it can
serve JNLP files with the correct mime type.
Move all your newly-signed Jar files onto the server. You may want to pick a
directory structure as follows to allow for multiple operating system support with
SWT.
/base
jar1.jar
jar2.jar
/swt
/win
swt.jar
swt_native_libs.jar
...
/osx
swt.jar
swt_native_libs.jar
...
/linux
swt.jar
swt_native_libs.jar
...
4. Create the JNLP File
The JNLP file is what brings the Java Web Start tool together. It is an XML file (but it ends with a .jnlp extension)
that describes where Java Web Start can find the Jar archive, what Jar files are
used in the applications, and what native files should be downloaded - depending
on the current platform. Here is a sample of a JNLP file that includes SWT support (named app.jnlp):
<?xml version="1.0" encoding="utf-8"?>
<jnlp
spec="1.0+"
codebase="http://www.someserver.com/your-path-to-web-start-app/" href="app.jnlp">
<information>
<title>App Title</title>
<vendor>App Vendor</vendor>
<homepage href="http://www.someserver.com/app-homepage/"/>
<description>App Description</description>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.4+"/>
<jar href="yourappjar.jar"/>
<jar href="included_lib1.jar"/>
<jar href="included_lib2.jar"/>
<jar href="included_lib3.jar"/>
</resources>
<resources os="Windows">
<jar href="swt/windows/swt.jar"/>
<nativelib href="swt/windows/swt_native_libs.jar"/>
</resources>
<application-desc main-class="com.yourdomain.YourAppClassName"/>
</jnlp>
5. Create a Link
Now, just create an HTTP link to the JNLP file. It should automatically start
Java Web Start if Java is integrated into your browser. Java Web Start will do
the rest. If you run into problems, Java Web Start will give you enough debugging
information to point you in the right direction.
When setting up the HTTP server, you must specify the JNLP mime type as a mime type
on the server. This way, the browsers that have Java installed correctly will be able
to launch the Java Webstart tool automatically when the link is clicked.
Some Pointers
1. Java Web Start can be served from a Windows file share.
This is helpful when you do not want to set up a web server just for serving Jar
files or do not want to incur the extra maintenance costs - and all your clients
are Windows machines. For more information read this article.
2. Java Web Start updates check Jar file integrity.
When Java Web Start detects a new Jar file on the server, it will download
it and thoroughly check its integrity and validity. Among the advantages of having
a more secure deployment environment, this means that you can deploy new versions
without worrying about users downloading corrupt versions of your application. You
can update the application during normal work hours.
3. Java Web Start and Mac OSX
As of this writing, SWT on Mac OSX needs to be run in a different thread configuration
than the standard Apple JVM default. This can be easily accomplished on the command line
by providing a switch, but Java Web Start for Java 1.4* does not support the switch.
Author
Written by Nathan Callender
Application Developer
October 12, 2005
Related Sources
Java Web Start Official Guide by Sun
Unofficial Java Web Start FAQ
Interested in implementing technology with SWT but need help?
Our consultants would be happy to help.
Contact us here.
|