Deploying WebRenderer via Java WebStart







Java WebStart is a process of deploying Java applications over the internet. WebStart applications are acompanied by some specific files including a JNLP file. A core part of the JNLP file is the codebase tag. This tag must point to the server on which your application resides. Such as: codebase="http://www.webrenderer.com/webstart/"

Core Requirements

The following example demonstrates how to create and launch a WebStart application with a basic Java application called TestBrowser.java. This example can be applied to the TestBrowser.java file that is included with WebRenderer. From a console:

1. Compile the Java file and package this into TestBrowser.jar

    javac -classpath webrenderer-swing.jar;. TestBrowser.java

Other platforms:
    javac -classpath webrenderer-swing.jar:. TestBrowser.java

jar -cvf TestBrowser.jar *.class

2. Sign all JARs with the same key file

This includes webrenderer-swing.jar, all the specific platform JARs that may be used with WebRenderer and the newly created TestBrowser.jar containing our Java application.

Key file generation:

keytool -genkey -keystore WRKeystore -alias wrstore

The file "WRKeystore" is now created.

JAR signing:

jarsigner -keystore WRKeystore <jarname> wrstore

e.g. to sign webrenderer-swing.jar

jarsigner -keystore WRKeystore webrenderer-swing.jar wrstore

3. Write the JNLP file

Here's an example of a file called TestBrowserAllPlatforms.jnlp (please note the Security section).
It shows how the JAR files are picked based on the platform and architecture. Note that the architecture used (32-bit or 64-bit) will be the same as the Java architecture that is launched by the host browser.

codebase="{Set the base URL here where all jars stored. For example http://www.webrenderer.com/webstart/}"

    <j2se version="1.4+"/>
    <jar href="TestBrowser.jar"/>
    <jar href="webrenderer-swing.jar"/>

<resources os="Windows" arch="amd64">
    <jar href="webrenderer-swing-windows64.jar"/>
    <jar href="corecomponents-swing-windows64.jar"/>

<resources os="Windows" arch="x86">
    <jar href="webrenderer-swing-windows32.jar"/>
    <jar href="corecomponents-swing-windows32.jar"/>

<resources os="Linux" arch="amd64">
    <jar href="webrenderer-swing-linux64.jar"/>
    <jar href="corecomponents-swing-linux64.jar"/>

<resources os="Linux" arch="i386 x86">
    <jar href="webrenderer-swing-linux32.jar"/>
    <jar href="corecomponents-swing-linux32.jar"/>

<resources os="Mac\ OS\ X" arch="x86_64">
    <jar href="webrenderer-swing-osx64.jar"/>
    <jar href="corecomponents-swing-osx64.jar"/>

<resources os="Mac\ OS\ X" arch="i386 x86">
    <jar href="webrenderer-swing-osx32.jar"/>
    <jar href="corecomponents-swing-osx32.jar"/>

<application-desc main-class="TestBrowser"/>

4. Link to the JNLP file from a webpage

This can be done in an HTML file with a simple link, such as:

<a href="TestBrowserAllPlatforms.jnlp">Launch WebRenderer Swing - TestBrowser</a>

Using this method to deploy will ensure the correct files are downloaded to the client WebStart based on the platform you are running, amounting to an efficient cross-platform distribution.

Closing WebRenderer when your application terminates

You must call System.exit(0); when you close your Java WebStart application, to destroy the WebRenderer instance. If you do not call System.exit(0) your application will still be running without a Window. Each time the application is run again, it will create a new Java process that will consume resources.






Copyright JadeLiquid Software - www.jadeliquid.com