Java WebStart Applications

From ActiveMathWiki

To implement your application as a Java WebStart application you need to do the following:

  • write a jnlp file and put it into ActiveMath's webapps/ActiveMath/jnlp folder
  • catch in your Java Application parameters that are conveyed by ActiveMath through the jnlp file

JNLP File

The JNLP file is an XML document. Hence it starts with an XML file declaration.

  <?xml version="1.0" encoding="UTF-8"?>

The jnlp element needs to know where to find your application's resources. This is declared in the codebase attribute of the jnlp element. hosturl is a velocity template which is substituted at runtime by the host url of the ActiveMath server.

  <jnlp codebase="${hosturl}assembly/">

If you like you can provide some branding information about your application, e.g., title, vendor, icon, or splash image. This information is displayed during the download of required packages.

  <information>
       <title> Title </title>
       <vendor> Vendor Name </vendor>
       <icon href="toolIcon.jpg"</icon> 
       <icon kind="splash" href=tool_splash.jpg"</icon> 
  </information>

Security is a big issue. For simplicity, we allow everything.

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

The resources elements provides runtime information for your application. In our case, we fix the java version to be used to 1.4 or higher. Then we provide a list of properties. These values are velocity templates which are substituted by ActiveMath at runtime. Possible values are:

  • mbaseRef.url: URL to access the knowledge base
  • userManager.url: URL to access the user manager
  • language.default: the user's language
  • user.id: the user's id
  • user.name: the user's name
  • hosturl: The URL to the host
  • book: book identifier used for assembly tool
  • file: ...

Finally, by the jar element you specify which packages are required and where to find them rlative to the codebase.

  <resources>
    <j2se version="1.4+"/>
    <property name="mbaseRef.url" value="${xmlrpcManager.addServerWithPrefix('mbaseRef',$mbaseForXmlRpc,$appSession)}"/>
    <property name="userManager.url" value="${xmlrpcManager.addServerWithPrefix('um',$userManager,$appSession)}"/>
    <property name="language.default" value="${lang}"/>
    <property name="user.id"   value="${user.id}"/>
    <property name="user.name" value="${user.name}"/>
    <property name="file"      value="${file}"/>
    <property name="hosturl"   value="${hosturl}"/>
    <property name="book"      value="${book}"/>
           
    <jar href="lib/assembly.jar"/>
    <jar href="lib/activemath-slim.jar"/>
    <jar href="lib/thirdParty.jar"/>
 </resources>

The last element tells Java WebStart which class to invoke to start the application.

  <application-desc   
    main-class="org.activemath.assembly.JNLPStart"/>
  </jnlp>

Catch Parameters in Application

This is quite simple: just invoke System.getProperty on the property name used in the jnlp file. In our example it looks like follows:

  System.getProperty("language.default", "de");
  System.getProperty("user.id", "anton"); 
  System.getProperty("user.name", "Anton");
  System.getProperty("book", "null");
  System.getProperty("mbaseRef.url", "http://127.0.0.1:27000/"));
  System.getProperty("hosturl", "http://127.0.0.1:8080/"));
  System.getProperty("userManager.url", null));