Introduction

This page lists some EL4ANT extensions done in projects that can be reused in some way in other projects. Eventually, they can be published later as PlugIns.

Web Start

The following plugin creates a web start JNLP file from a simple template and the module jars and dependencies. It signs the jars using an existing keystore and copies everything in a destination directory.

  • A web start module must be runnable.

  • Attributes
    • webstart.application (mandatory): name of the web start application (name of the directory and .jnlp file).
    • webstart.mainclass (mandatory): the class containing the main() method starting the application.
    • webstart.homepage (mandatory): application homepage URL appearing in the JNLP.
    • webstart.dest.dir (optional): where the jnlp file and jars are copied. Defaults to dist/webstart

  • In the directory module/webstart directory, the following files appear
    • name.jnlp The JNLP file template. (See below an example). The following variables are replaced:
      • @webstart.homepage@.
      • @webstart.mainclass@.
      • @webstart.jar.list@ computed from the module jars and dependencies.

  • Typically, the following files are also in the webstart directory,
    • icon.gif The icon of the application
    • splash.jpg The splash image

  • The keystore by default is module/keystore/webstart.keystore, passphrased with webstart and containing a key alias named webstart.

Plugin code

<?xml version="1.0"?>
<project
  name="webstart"
  xmlns:antcontrib="antlib:net.sf.antcontrib"
  xmlns:el4ant="antlib:ch.elca.el4ant">
<description>
EL4Ant Webstart plugin.
</description>

  <target
    name="configure"
    description="[C] Configure the webstart plugin">

    <el4ant:plugin name="runtime" file="buildsystem/core/runtime.xml"/>

    <el4ant:buildgen action="include" target="webstart.include.startpoint"/>

    <el4ant:buildgen
      action="shortcut"
      target="create.webstart.module.eu"
      ifattribute="webstart.application">
      <param name="module"/>
      <param name="eu"/>
    </el4ant:buildgen>

  </target>

  <!-- Fake targets to load plugin file -->
  <target name="init"/>

  <!-- Targets following the next fake target are copied into the generated build.xml file -->
  <target name="webstart.include.startpoint"/>

  <!-- Targets from webstart.xml  -->

  <target
    name="create.webstart.module.eu"
    depends="init"
    description="[WEBSTART] Create a Webstart Application for the execution unit of a module">

    <el4ant:extendedproperty
      name="module.application"
      value="${webstart.application.${module}.${eu}}"/>

    <!-- Default value for overwritable parameters -->
    <property name="webstart.jar.excludes" value=""/>
            
    <antcontrib:if>
        <isset property="webstart.dest.dir.${module}.${eu}"/>
        <antcontrib:then>
            <el4ant:extendedproperty
               name="webstart.dir"
                value="${webstart.dest.dir.${module}.${eu}}"/>
        </antcontrib:then>
        <antcontrib:else>
            <property name="webstart.dir" value="dist/webstart/${module.application}"/>
        </antcontrib:else>
    </antcontrib:if>
    
    <!-- Check for the attribute -->
    <el4ant:extendedproperty
      name="module.runnable.property"
      value="runtime.runnable.${module}.${eu}"/>
    <el4ant:extendedproperty
      name="module.runnable.value"
      value="${runtime.runnable.${module}.${eu}}"/>
    <el4ant:extendedproperty
      name="module.application.property"
      value="webstart.application.${module}.${eu}"/>
    <fail message="The module execution unit ${module}.${eu} is not runnable.">
      <condition>
        <not>
          <and>
            <isset property="${module.runnable.property}"/>
            <istrue value="${module.runnable.value}"/>
          </and>
        </not>
      </condition>
    </fail>
    <fail message="The attribute 'webstart.application' is not set for ${module}.${eu}">
      <condition>
        <not>
          <and>
            <isset property="${module.application.property}"/>
          </and>
        </not>
      </condition>
    </fail>


    <!-- Make sure it is clean -->

    <delete
      failonerror="false"
      includeEmptyDirs="true"
      deleteonexit="false"
      dir="${webstart.dir}"/>
    <mkdir dir="${webstart.dir}"/>

    <el4ant:extendedproperty
      name="module.dependencies"
      value="${module.dependencies.${module}}"/>

 
      <el4ant:extendedproperty
         name="module.eu.classpath"
         value="${runtime.classpath.${module}.${eu}}"/>

   <!-- Create a file contaning the jnlp jar list -->
    <property name="webstart.jar.list.file" value="${webstart.dir}/jar-files.xml"/>
    <echo message="&lt;!-- JNLP jar list -->${line.separator}" file="${webstart.jar.list.file}"/>

    <!-- Copy the execution unit dependencies jars in webstart dir-->
    <antcontrib:for
      param="apath"
      list="${module.eu.classpath}"
      delimiter=":">
      <sequential>

        <antcontrib:if>
          <available file="@{apath}" type="file"/>
          <!-- Copy the jar file -->
          <antcontrib:then>
            <copy
              todir="${webstart.dir}"
              failonerror="true">
              <fileset
                file="@{apath}"
                excludes="${webstart.jar.excludes}"/>
            </copy>
            
            
            <basename property="jar.filename.@{apath}" file="@{apath}"/>
            
            <!-- Add the jar file to the jnlp jar elements -->
            <echo message="&lt;jar href=&quot;${jar.filename.@{apath}}&quot;/&gt;${line.separator}" 
                file="${webstart.jar.list.file}" append="true"/>
            
          </antcontrib:then>
        </antcontrib:if>

      </sequential>
    </antcontrib:for>

    <el4ant:extendedproperty
      name="module.path"
      value="${module.path.${module}}"/>
      
   <!-- Sign all jars -->
    <signjar keystore="${module.path}/keystore/webstart.keystore" alias="webstart" storepass="webstart">
        <fileset dir="${webstart.dir}">
           <include name="*.jar"/>
      </fileset>
    </signjar>

   <loadfile property="webstart.jar.list" srcFile="${webstart.jar.list.file}"/>

    <el4ant:extendedproperty
      name="webstart.homepage"
      value="${webstart.homepage.${module}.${eu}}"/>      
    <el4ant:extendedproperty
      name="webstart.mainclass"
      value="${webstart.mainclass.${module}.${eu}}"/>

   <copy todir="${webstart.dir}">
       <fileset dir="${module.path}/webstart/" excludes="*.jnlp"/>
    </copy>
    
    <copy todir="${webstart.dir}">
       <fileset dir="${module.path}/webstart/" includes="*.jnlp"/>
        <filterset>
            <filter token="webstart.homepage" value="${webstart.homepage}"/>
            <filter token="webstart.jar.list" value="${webstart.jar.list}"/>
            <filter token="webstart.mainclass" value="${webstart.mainclass}"/>           
        </filterset>
    </copy>

   <delete file="${webstart.jar.list.file}"/>

    <echo message="Webstart Application is available at ${webstart.dir}"/>

  </target>
  <!-- End  webstart.xml  -->
</project>

JNLP Template

Here is an example for the JNLP template. This example uses the JNLP Download Servlet (see below).

<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for Ingest Application -->
<jnlp
  spec="1.5+"
  codebase="$$codebase"
  href="$$name">
  <information>
    <title>e-Helvetica Ingest</title>
    <vendor>Swiss National Library</vendor>
    <homepage href="@webstart.homepage@"/>
    <description>Ingest Administration</description>
    <icon href="icon.gif"/>
    <icon kind="splash" href="splash.jpg"/>
    <shortcut online="false">
      <menu submenu="e-Helvetica"/>
    </shortcut>
  </information>
  <security>
      <all-permissions/>
  </security>
  <resources>
    <j2se version="1.5.0+" java-vm-args="-esa -Xnoclassgc"/>
    @webstart.jar.list@
  </resources>
  <application-desc main-class="@webstart.mainclass@"/>
</jnlp> 

JNLP Download Servlet

Optionally, one can use the JNLP Download Servlet. The jar file is provided with the Java 5.0 distribution in the examples directory.

This servlet automatically replaces some values like $$codebase and $$name. See http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/downloadservletguide.html.

      <servlet>
        <servlet-name>JnlpDownloadServlet</servlet-name>
        <servlet-class>jnlp.sample.servlet.JnlpDownloadServlet</servlet-class>
     </servlet>

     <servlet-mapping>
        <servlet-name>JnlpDownloadServlet</servlet-name>
        <url-pattern>*.jnlp</url-pattern>
     </servlet-mapping>

Revision: r1.1 - 20 Jun 2006 - 10:32 - LaurentBovet
EL4Ant > PlugIns > PluginIncubator
Copyright © 2004 by ELCA. All material on this collaboration platform should not be disclosed outside of ELCA.
Ideas, requests, problems regarding TWiki? Send feedback.