|
Java Web Start - Examples
This page offers examples of using services of the JNLP API.
Examples of using services of the JNLP API
Web start provides a number of services that make application
deployment easy for the developer, as well as safe and 'slick' for
the end user.
Here are a number of buildable demos of the javax.jnlp API
that can be launched directly from this page.
The build file, along with Java source, the JNLP templates &
any resources, are also linked.
This open source is offered under an LGPL licence.
| Launch |
Download |
Service(s) Demonstrated |
In Web Start |
| Description |
| Launch BasicService demo |
basicservice.zip (3 Kb) |
BasicService
|
1.0 |
|
Sandboxed demonstration of the methods of the BasicService
(getCodeBase(), isOffline(),
isWebBrowserSupported() & showDocument(URL)).
In Java 6+, a call to show another web start launch file
(e.g. BasiceService.showDocument(another.jnlp))
will be handed
directly to JavaWS, with no browser window appearing.
|
| Launch ClipService demo |
clipservice.zip (4 Kb) |
ClipboardService
|
1.0 |
|
Sandboxed demonstration of the methods of the ClipboardService.
|
| cache/#latesteg |
cache/#latestdl |
DownloadService
DownloadServiceListener
|
1.0 |
|
See the JWS - Lazy downloads page
for further details and discussion.
|
| Launch Application Installer demo
Launch Application Un demo
|
installer.zip (5 Kb) |
ExtensionInstallerService
|
1.0 |
|
Java web start (JWS) offers the installer-desc
element to identify an installer/uninstaller
for an application. The intent of the installer
is to do any application set-up/pull-down that
can not be handled by the standard JWS behaviour
of caching the classes/resources at 1st launch,
and clearing them at uninstall.
Two versions of this trivial application (a JLabel within a JFrame)
are offered. The first will pop an 'End User Licence Agreement' before application launch,
and it will appear either once (the user clicks 'OK') or as many times as the user wants
if they cancel it. Once the user chooses to OK the EULA, the application will appear.
The second version also ensures the end user has a Java version suitable
to call the uninstaller, which simply pops a JOptionPane that
thanks the user for their patronage.
Bug reports 6515728
& 6568950
refer.
|
| Launch File Service demo
Launch File Service (sandboxed) demo |
filetest.zip (5 Kb) |
FileOpenService
FileSaveService
FileContents
ExtendedService (1.5+)
|
1.0/1.5 |
|
The JNLP API provides services to allow even sandboxed applications to
open and write to local files, with the specific permission of the end user.
If the application is trusted, a call to openFileDialog()
(or equivalents) will go unchallenged and simply proceed to show a file chooser.
Sandboxed applications, on the other hand, will invoke a trust dialog asking
the user if they want to allow the program to access local files. The user can
allow it (just once, or for the rest of that run), or cancel the request.
Note that the launch file prompts the user to associate file extension
.zzz (simply a file type unlikely to clash with existing file associations)
of content type text/sleepytime. The build file
allows the file-type to be set at build time, see the build.xml
in the distributable for details.
Java 1.5+ VM's should be able to provide a better user
experience for sandboxed applications, in regards to 'double click-open'
files. A 1.5+ VM comes complete with the ExtendedService,
which allows us to open a FileContents object
directly (without the file chooser), as soon as the user OK's that file.
This code has been mentioned on the Sun web-start forum under the title
Example of using the JNLP file API *.
Caution: The FSS has a number of quirky aspects, see
6646622
&
6646617.
|
| Launch Random Access File demo |
jnlpraf.zip (4 Kb) |
JNLPRandomAccessFile
|
1.0 |
|
Sandboxed demonstration of the JNLPRandomAccessFile class of the
web start API.
The Head'n'Tail application offers text areas in a split pane.
The top text area shows the 'head' of any file the user chooses, while the lower
text area displays the file's 'tail'. A combo box on top of the GUI determines
the maximum number of bytes read and displayed (from 100-2000 bytes).
The JNLPRandomAccessFile instance provides methods that
allow us to jump directly to the point near the end of the file from which
to read the 'tail'. This represents a relatively trivial use of the
JNLPRandomAccessFile - which also offers methods for
reading and writing of Boolean, Byte, Float, Char, UTF, lines..
as well as moving around the file as needed - and so could
represent an efficient way to access large data files.
This demo also uses FileOpenService &
FileContents,
examined in the FileOpen/SaveService example.
|
| Launch PersistenceService demo |
persistserv.zip (4 Kb) |
PersistenceService
|
1.0 |
|
Demonstration of the methods of the PersistenceService.
The simple 'JotPad'
application stores notes the user types in, as well as remembering the application's
location, size, and PLAF.
|
| Launch PrintService demo |
printservice.zip (4 Kb) |
PrintService
|
1.0 |
|
Sandboxed demonstration of the PrintService.
This demo also uses FileOpenService &
FileContents,
examined in the FileOpen/SaveService example.
|
| Launch Single Instance Application demo |
singleapp.zip (3 Kb) |
SingleInstanceService
SingleInstanceListener
|
1.5 |
|
The SingleInstanceService ensures there is only one version
of an application on-screen at any given moment.
If the user opens the program while an instance
is already on-screen, the application's notification method is called, and
the developer gets to decide what action needs to be taken (such as opening
a new editing tab with another file, or otherwise updating the parameters
of the current instance).
This version simply alerts the user that new arguments have been received,
and adds the time and arguments to the application's editing area.
This code has been mentioned on the Sun web-start forum under the title
Example - using web-start SingleInstanceService *.
It was also used as the test case in the bug report
6631056.
|
The Sun forum on
Deploying - Java Web Start & JNLP is the best first place to seek help
on matters relating to web-start. The author (who appears under
Sun forums ID
AndrewThompson64) alone,
has assisted many
developers through to a successful application deployment.
The threads linked from this page
have further details and discussion of the services being used.
Some also include the text of the Java source, build file and JNLP template.
Any comments, questions or test results are most welcome on the forum,
but note that the author is also available for consultancy on web-start
related technologies.
|