Tutorial 02 : Deploying application using JWS

We have seen on the first tutorial how the application is deployed in the client side.
Now, we will see how to create the JWS application.

We will begin from an existing application that uses two external API's : Jogl (OpenGL) and NativeFmodEx (FMOD Ex).
You will see how use jws for deploying your applocation with these two API's.

The resulting jws application is here : Geometry
 

The example used for this tutorial is taken from NativeFmodEx (a Java port of an example included with FMOD Ex).
This example is composed of :

The difficulty here is to link the two requiered API's, especially the libraries that depends on the target platform.
 

In this example, we uses two API's that uses libraries. To use them, your application need to all permission.
To obtain these permissions, your need to sign all jars you will use.

First thing to do is to generate a certificate. This will indicates where the application come from (compagny, location ...). The certificate is used to authentify the application.
To generate this certificate, use the keytool utility from the jdk.

keytool

keytool -genkey -keystore %SIGN_NAME% -alias %SIGN_NAME%

Replace %SIGN_NAME% by your key name ( ~ "certificate name").


Certificate

Keytool utility will generate a file named %SIGN_NAME% , storing the certificate and the key.
 

Now you have a certificate, you can sign your jars. Use for this the jarsigner tool, also in the jdk.
This is used to verify the signature (authenticity) and integrity of the jar during its use.
 

jarsigner

jarsigner -keystore .\%SIGN_NAME% -storepass %PASS% -keypass %PASS% %JAR%.jar %SIGN_NAME%

Replace %SIGN_NAME% by your key name ( ~ "certificate name").
        %PASS%      by your key password.
        %JAR%       by the filename of the jar to be signed.
 

A jnlp file is an xml file in wich you put all informations about your application.

In the tag information, you can give your personal information, the application description ...
The other tags are used to give informations for running the application.

Here are the three jnlp file used to run the example :
 

JWS-Tutorial02.jnlp

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://127.0.0.1/JWS" href="JWS-Tutorial02.jnlp">
    <information>
        <title>Tutorial 02</title>
        <vendor>Jerome JOUVIE (Jouvieje)</vendor>
        <homepage href="http://jerome.jouvie.free.fr/"/>
        <description>JWS Tutorial 02</description>
        <offline-allowed/>
    </information>

    <security>
        <all-permissions/>
    </security>

    <resources>
        <j2se version="1.5+"/>
        <jar href="JWS-Tutorial02.jar"/>
        <extension href="http://127.0.0.1/JWS/NativeFmodEx/NativeFmodEx.jnlp" name="NativeFmodEx"/>
        <extension href="http://127.0.0.1/JWS/Jogl/Jogl.jnlp" name="Jogl"/>
    </resources>

    <application-desc main-class="org.jouvieje.FmodEx.Examples.Geometry_"/>
</jnlp>

 

NativeFmodEx.jnlp

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://jerome.jouvie.free.fr/JNLP/" href="NativeFmodEx.jnlp">
    <information>
        <title>NativeFmodEx</title>
        <vendor>Jerome JOUVIE (Jouvieje)</vendor>
        <homepage href="http://jerome.jouvie.free.fr/"/>
        <description>You want to use FMOD Ex (www.fmod.org) in Java ? I've created NativeFmodEx for you.</description>
        <offline-allowed/>
    </information>
    <security>
        <all-permissions/>
    </security>

    <resources>
        <j2se version="1.4+"/>
        <jar href="NativeFmodEx.jar"/>
    </resources>

    <resources os="Windows">
        <j2se version="1.4+"/>
        <nativelib href="FmodEx-win.jar"/>
        <nativelib href="NativeFmodEx-win.jar"/>
    </resources>
    <resources os="Linux">
        <j2se version="1.4+"/>
        <nativelib href="FmodEx-linux.jar"/>
        <nativelib href="NativeFmodEx-linux.jar"/>
    </resources>

    <component-desc />
</jnlp>

 

Jogl.jnlp

<?xml version="1.0" encoding="utf-8"?>
<jnlp codebase="https://jogl.dev.java.net/webstart/" href="jogl.jnlp">
    <information>
        <title>JOGL</title>
        <vendor>Sun Microsystems, Inc.</vendor>
        <homepage href="http://jogl.dev.java.net/"/>
        <description>JOGL</description>
        <description kind="short">Java programming language binding for the OpenGL 3D graphics API.</description>
        <offline-allowed/>
    </information>
    <security>
        <all-permissions/>
    </security>

    <resources>
        <jar href="jogl.jar"/>
    </resources>
    <resources os="Windows">
        <nativelib href="jogl-natives-win32.jar"/>
    </resources>
        <resources os="SunOS" arch="sparc">
        <nativelib href="jogl-natives-solsparc.jar"/>
    </resources>
        <resources os="SunOS" arch="x86">
        <nativelib href="jogl-natives-solx86.jar"/>
    </resources>
        <resources os="Linux">
        <nativelib href="jogl-natives-linux.jar"/>
    </resources>
        <resources os="Mac OS X">
        <nativelib href="jogl-natives-macosx.jar"/>
    </resources>

    <component-desc />
</jnlp>

 

The tag security define the secutity level of the aplication, here we need all permissions (because of use of native libraries). In this case, all jars must be signed.

The tag resources list all resources necessary for running the application. A resource can be a jar (tag resources), a library (tag nativelib), an extension (tag extension).
To use a library, you should packed it into a signed jar (create a jar, then sign it). An extension is a sub jnlp file. It is commonly used for external APIs, code shared between differents applications ...

 

First, you need to put the jnlp and the jar file in the location refered by the fields codebase and href (declared in the jnlp file).

To execute the application from any of your page, add just a classic html link that points toward the jnlp file. In case of use of multiple jnlp files, points toward the main jnlp file.

HTML link

<A HREF="http://www.mysite.com/JWS/MyApplication.jnlp"></A>

 

The server hosting the application must associate the MIME type application/x-java-jnlp-file with the jnlp extension.
MIME type tell the browser which application should be used to execute the file.

When this association is done, executing the application under Firefox look like :


Association

  What can we do if we can't associate MIME type ?

The association can be done using php. Just add these few lines at the beginning, and change the extension of the jnlp file to *.php.
 

MIME Association with PHP

<?
    header("Content-Type: application/x-java-jnlp-file; name=FILE_NAME.jnlp");
    header("Content-disposition: attachment; filename=FILE_NAME.jnlp");
?>

Change FILE_NAME by the original file name of your jnlp file.
 

 

 

Previous turorial

Back

 

Last modified on 01/07/2010
Copyright © 2004-2010 Jérôme JOUVIE - All rights reserved. http://jerome.jouvie.free.fr/