WebStart
From Rxtx
Contents |
Introduction
Using Java Web Start technology, standalone Java software applications can be deployed with a single click over the network. This page explains what you need to do to make you application web startable.
The first thing to do is create two JNLP files, one for the libraries and one for your application. While this approach is not strictly necessary, it helps provide a separation between what is usable between projects and what is specific to a given project. Below are two sample JNLP files that you can use as a starting point.
JNLP For your application:
<?xml version="1.0" encoding="utf-8"?> <jnlp codebase="http://myserver/webstart/applications" href="gpsviewer.jnlp"> <information> <title>GPSViewer</title> <vendor>ajmas</vendor> <homepage href="http://mysite/"/> <description>Program displaying data from NMEA compatible GPS device</description> <description kind="short">Displays data from a NMEA GPS device</description> <offline-allowed/> </information> <security> <all-permissions/> </security> <resources> <j2se href="http://java.sun.com/products/autodl/j2se" version="1.5+"/> <jar href="geonavapps.jar" main="true"/> <jar href="geonav.jar" main="false"/> <extension name="rxtx" href="http://myserver/webstart/rxtx/rxtx.jnlp" /> </resources> <application-desc main-class="osj.geonav.gpsviewer.GPSViewer"/> </jnlp>
JNLP for library:
<?xml version="1.0" encoding="utf-8"?> <jnlp codebase="http://myserver/webstart/rxtx/" href="rxtx.jnlp"> <information> <title>RXTX</title> <vendor>ajmas</vendor> <homepage href="http://www.rxtx.org"/> <description>Java API for serial port communication</description> <description kind="short">Java API for serial port communication.</description> <offline-allowed/> </information> <security> <all-permissions/> </security> <resources> <jar href="rxtx-comm.jar" /> </resources> <resources os="Windows" arch="x86"> <nativelib href="rxtx-comm-natives-windows-i586.jar" /> </resources> <resources os="Linux" arch="i686"> <nativelib href="rxtx-comm-natives-linux-i686-32.jar" /> </resources> <resources os="Linux" arch="i386"> <nativelib href="rxtx-comm-natives-linux-i686-32.jar" /> </resources> <resources os="Linux" arch="x86"> <nativelib href="rxtx-comm-natives-linux-i686-32.jar" /> </resources> <resources os="Mac OS X" > <nativelib href="rxtx-comm-natives-macosx-universal.jar" /> </resources> <component-desc /> </jnlp>
It should be noted that the 'codebase' attribute is an absolute URL and generally points back to the file that contains it, so if your JNLP is located at
http://www.mysite.com/myapp.jnlp
then the codebase URL should match.
The native libraries are all added to individual archives for each platform, the library file being without a path prefix. For example the contents of the 'rxtx-comm-natives-macosx-universal.jar' would be something as follows:
META-INF/MANIFEST.MF META-INF/ librxtxSerial.jnilib
All the Java archives referenced by the JNLP files should be signed, so that the application and libraries can access native functions, such as accessing the serial port. See the section on signing your Jars.
Signing Your Jars
Generating the Keys
The following instructions explain how to sign a JAR using a self signed certificate.
To generate the key:
keytool -genkey -alias alias-name -keystore keystore-name
The alias-name and keystore-name are optional and if not provided default to mykey and .keystore (in your home directory). If the keystore that is specified does not exist, then it will be created, otherwise it will modify the existing keystore. After typing this command, you will be asked for the keystore password (or to create one if the keystore does not yet exist). At this point you will be asked some questions:
What is your first and last name? [Unknown]: your name What is the name of your organizational unit? [Unknown]: What is the name of your organization? [Unknown]: My Company What is the name of your City or Locality? [Unknown]: Montreal What is the name of your State or Province? [Unknown]: QC What is the two-letter country code for this unit? [Unknown]: CA Is <CN=your name, OU=Unknown, O=My Company, L=Montreal, ST=QC, C=CA> correct? [no]: y
After having specifed yes, you can either specify a different password for the key, or use the same one as the key store.
Note that that the key is valid for 90 days by default, and if you wish for a longer period then you should use the -validity option.
Signing the Jar
To sign the Jar use the following jarsigner command:
jarsigner -keystore keystore-name -storepass keystore-password -keypass key-password jar-file alias-name
For example, if your keystore name is 'myKeyStore', with both keystore password and key passwords being pass123, the jar you wish to sign being myapp.jar and the key name being 'mykey', then you would use the command as follows:
jarsigner -keystore myKeyStore -storepass pass123 -keypass pass123 myapp.jar mykey