You are hereAria User Guide / Section III: In Depth / Packaging and Deployment

Packaging and Deployment


By luano - Posted on 14 January 2009

This chapter will describe the steps involved in packaging and deploying a Aria application. It will cover topics such as running from the command line, from a website using Java webstart, creating native executables and installation wizards.

Package your project

For convenience, it can be useful to create a batch file which will package all of the resource and class files and install them into a single jar file. So, by creating the following batch file in the root of a Aria project all of the project files can be merged into a single jar.

Sample jar script

  1. # Create the file with a mainfest file
  2. c:\j2sdk1.4.2_03\bin\jar cvf bundle.jar META-INF/MANIFEST.MF
  3. # navigate to the resources directory and jar it's contents.
  4. # Repeat this for all resource files
  5. cd resources
  6. c:\j2sdk1.4.2_03\bin\jar uvf ../bundle.jar *.*
  7. cd ..\pages
  8. c:\j2sdk1.4.2_03\bin\jar uvf ../bundle.jar *.*
  9. cd ..\images
  10. c:\j2sdk1.4.2_03\bin\jar uvf ../bundle.jar *.*
  11. cd ..\classes
  12. c:\j2sdk1.4.2_03\bin\jar uvf ../bundle.jar *.*
  13. # Extract the contents of the jars which need to be included
  14. # in the application into a tmep directory and jar them.
  15. cd ..\lib
  16. rd temp
  17. md temp
  18. cd temp
  19. ########## STARTED EXTRACTING JARS ############
  20. c:\j2sdk1.4.2_03\bin\jar xvf ../AriaRuntimeCommon.jar
  21. ########## FINISHED EXTRACTING JARS ###########
  22. c:\j2sdk1.4.2_03\bin\jar uvf ../../bundle.jar *.*
  23. cd..\..

The first line in this script references a file called META-INF/MANIFEST.MF which looks like...

The manifest file

  1. Manifest-Version: 1.0
  2. Main-Class: org.formaria.swing.Applet

This file simply tells the jar that the org.formaria.swing.Applet class needs to be loaded when the jar file is run. Note that the startup file is not specified in which case the Applet class looks for and uses the startup.properties file if it is present.

You should now be able to run the application simply by double-clicking the jar file.

Running a Aria application from the command line

Again, it is easier to create a batch file to launch the application. So, by creating a file ` run.bat ' in the root of the Aria project folder, the application can be launched using the jar which was created in the previous section

Launch Aria with the command line

  1. java.exe -cp bundle.jar org.formaria.swing.Applet startup.properties

The startup.properties parameter is not necessary if the startup file is called ` startup.properties '.

If you do not wish to bundle all of your jars into a single jar you may wish to create the following file to launch the application.

Specify the jars separately

  1. java -cp .;.\lib\AriaRuntimeCommon.jar;.\bundle.jar;
  2. org.formaria.swing.Applet startup.properties

In this case you will want to modify the bundle.bat file so as to remove the commands which jar the contents of the dependancies. The following lines should be removed from the bundle.bat file.

Lines to be remove from the bundle.bat file

  1. # cd ..\lib
  2. # rd temp
  3. # md temp
  4. # cd temp
  5. ########## STARTED EXTRACTING JARS ############
  6. # c:\j2sdk1.4.2_03\bin\jar xvf ../AriaRuntimeCommon.jar
  7. ########## FINISHED EXTRACTING JARS ###########
  8. # c:\j2sdk1.4.2_03\bin\jar uvf ../../bundle.jar *.*
  9.  

Running a Aria application using Java Web Start

Java Web Start is used where applications need to be deployed over the internet but do not run within the confines of a web browser. The client machine which attempts to run the application must have a valid Java runtime installed

Java Web Start reads the contents of a JNLP file which resides on a webserver in order to initialise an application. Before the application can be used, however, the jar file which is to be used needs to be signed with a code signing digital certificate. This certificate will be registered to your company name and can be purchased from one of the following.

  1. Sources for code signing certificates

Company

URL

Verisign

http://www.verisign.com/products-services/security-services/code-signing/digital-ids-code-signing/

Thawte

http://www.thawte.com/codesign/

GlobalSign

http://www.globalsign.net/digital_certificate/objectsign/index.cfm

Alternatively you can create your own test certificate using the tools supplied with the JDK (the keytool tool with the -selfcert option). Once the certificate has been created you need to import it into your keystore, if you don't already have a keystore then you will need to create one.

Generate a new keystore for you certificates

  1. c:\jdk1.5.0\bin\keytool
  2. -genkey
  3. -alias my_keystore
  4. -keypass mykeypassword
  5. -keyalg RSA
  6. -keystore mycompany.keystore
  7. -storepass mystorepassword

The new keystore will be created in the current working directory. Next, to start the process of signing you need to generate a certificate signing request:

Generate a certificate signing request

  1. c:\jdk1.5.0\bin\keytool
  2. -certreq
  3. -alias my_keystore
  4. -keystore mycompany.keystore
  5. -file certreq.txt

The output file certreq.txt needs to be sent to the signing authority by cutting and pasting the content into the forms provided on the authorities website (the process may differ from company to company). Using the new certificate the jar file can be signed using the JDK. When the process is complete you should then receive a new certificate from the signing authority. The new certificate needs to be imported into your keystore:

Import the new certificate

  1. c:\jdk1.5.0\bin\keytool -alias my_keystore -keypass mykeypassword -keystore mycompany.keystore -storepass mystorepassword -import -file cert.txt -trustcacerts

The keystore is now ready for use and you can sign the bundle.jar file using the following command, so that a new version of the jar, bundleS.jar , is output.

Signing the jar file

  1. jarsigner
  2. -keystore mycompany.keystore
  3. -signedjar bundleS.jar bundle.jar

The signed jar can now be deployed to a webserver along with a JNLP file. For the new bundleS.jar file the JNLP file might look like...

A sample JNLP file

  1. <jnlp spec="1.0+" codebase="http://www.mydomain.com/demo/">
  2. <information>
  3. <title>Aria Application</title>
  4. <vendor>My Company Ltd</vendor>
  5. <homepage href="http://www.mydomain.com/demos" />
  6. <description kind="">Some application</description>
  7. <description kind="tooltip">Aria Application</description>
  8. <offline-allowed />
  9. </information>
  10. <resources>
  11. <j2se version="1.4+" />
  12. <jar href="lib/AriaRuntimeCommonS.jar" main="true" download="eager"/>
  13. <jar href="lib/bundleS.jar"/>
  14. </resources>
  15. <application-desc main-class="org.formaria.swing.Applet">
  16. <argument>startup.properties</argument>
  17. </application-desc>
  18. <security>
  19. <all-permissions />
  20. </security>
  21. </jnlp>

In this example the JNLP file can be invoked by referencing http://www.mydomain.com/demos/aria.jnlp

The .jnlp extension needs to be included in the mime types for the webserver it is running on if not already done so. The method of doing this varies accross webservers so the documentation for the webserver should be referred to.

Note that in the above example the Aria jars are also listed, but you could just include everything in the one jar file. However, leaving the Aria code in separate jars means that you can reuse the jars in other applications and if the same URL is used then the jars will not need to be downloaded again by the user's system. Also note that all the jars need to be signed by the same certifcate (i.e. your certificate) and therefore the Aria jars are not supplied in a signed form. Finally, the main="true" attribute tells JWS that the jar contains the entry point, or main method, which is used to start the application.

NetBeans 5.0 supports an add-on module to edit JNLP files. Check the NetBeans Update Center for details.

Additional Java Web Start documentation

Resource

URL

JWS Developer's guide

/docs/guide/javaws/developersguide/contents.html

Signing tools

/docs/tooldocs/index.html#security

Java deployment guide

/docs/guide/deployment/deployment-guide/contents.html

JWS examples

/docs/relnotes/samples.html

NetBeans JWS plug-in

http://www.netbeans.org/kb/articles/matisse-jaws.html

JNLP visual editor

http://public.wuapaa.com/public/NetBeans/

Setting up a JWS extension

If you have more than one application based upon Aria you may wish to share the core jars between applications, so that they are not repeatedly downloaded for each application. The JNLP specification allows resources to be specified as an extension, and the extension can contain the common jars (with the restriction that the jar containing the main method must be referenced in the primary JNLP file).

A sample JNLP file

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <jnlp spec="1.0+" codebase="http://www.mydomain.com/demo/">
  3. <information>
  4. <title>Aria Application</title>
  5. <vendor>My Company Ltd</vendor>
  6. <homepage href="http://www.mydomain.com/demos" />
  7. <description kind="">Some application</description>
  8. <description kind="tooltip">Aria Application</description>
  9. <offline-allowed />
  10. </information>
  11. <resources>
  12. <j2se version="1.4+" />
  13. <jar href="lib/AriaRuntimeCommonS.jar" main="true" download="eager"/>
  14. <extension name="Aria" href="aria.jnlp"/>
  15. <jar href="lib/bundleS.jar"/>
  16. </resources>
  17. <application-desc main-class="org.formaria.swing.Applet">
  18. <argument>startup.properties</argument>
  19. </application-desc>
  20. <security>
  21. <all-permissions />
  22. </security>
  23. </jnlp>
  24.  
  25. <?xml version="1.0" encoding="utf-8"?>
  26. <jnlp spec="1.0+" codebase="http://www.mydomain.com/demos/" href="aria.jnlp">
  27. <information>
  28. <title>Aria</title>
  29. <vendor>Formaria Ltd.</vendor>
  30. <homepage href="http://www.mydomain.com/demos"/>
  31. <offline-allowed/>
  32. </information>
  33. <resources>
  34. <jar href="lib/AriaRuntimeCommon.jar" main="false"/>
  35. <jar href="lib/jxl.jar"/>
  36. </resources>
  37. <component-desc/>
  38. </jnlp>

Deploying a webstart application via CD

Once you have created and deployed a JWS applicationit is possible to put that application on CD so that the features of JWS are available to anyone who has installed from CD. The result is that you can distribute your application via CD or other routes, install that application onto the desktop and into the JWS cache so that the application will run in an off-line mode and so that when on-line it will check for updates.

To install into the JWS cache it is necessary to import the jar files. Assuming you have copied your server's version of the application jnlp and jar files, you then need to create an additional file ( install.bat or install.cmd on Windows):

Import the jars into the JWS cache

  1. @echo off
  2. SET DRIVE=%0
  3. SET DRIVE=%DRIVE:&#126;1,1%
  4. c:\jdk1.5.0\bin\javaws
  5. -codebase file:///%DRIVE%:/myapp/
  6. -import %DRIVE%:/myapp/myApp.jnlp

Once this command file is run the files will be imported into the JWS cache and depending on the content of the JNLP file, desktop and menu shortcuts may be setup.

You will probably want to add an auto install option to your CD, and if so, you should use the installer to kick of the above commands and possible start the application following successful installation.

This installation mechanism has been packaged in an installed for CDs. Please contact Formaria for futher details.

Running a Aria application from a web page

Using the bundle.jar file from the first section in this chapter, a web page can be created which will start it as an applet. This assumes that the project was written using the AWT packages and not the swing packages.

Applet tag for the applet

  1. <APPLET style="height=100" archive="../lib/bundle.jar"
  2. width=100 code=org.formaria.awt.Applet>
  3. <PARAM NAME="startfile" VALUE="startup.properties">
  4. </APPLET>

It is possible to start an application written with the Swing packages as an applet by using the object tag

Starting a swing application from a browser

  1. <Object
  2. classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
  3. codebase="http://java.sun.com/products/plugin/1.1/jinstall-11-win32.cab#Version=1,3,0,0"
  4. width=50 height=50>
  5.  
  6. <param name="code" value="org.formaria.swing.Applet.class">
  7. <param name="codebase" value="./lib/bundle.jar/">
  8. <param name="startfile" value="startup.properties">
  9. </object>

Creating a setup for your Aria application

There are a number of ways of deploying your Aria application from custom written deployments to third pary installers. In this section, however, the installer which will be used is izPack, an open source installer which can be downloaded from http://www.izforge.com/izpack/

The version of izPack being used in this section is 3.6.1. For other versions or more advanced information please visit the izforge website.

Setup izPack by downloading the IzPack-install-3.6.1.jar file and double-clicking it to install. For these examples it is assumed that izPack is installed into c:\programmer\IzPack

For convenience it is easier to create an izPack directory under the Aria project root directory. Within this directory the following izPack configuration xml file can be created.

The izPack configuration file

  1. <?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
  2. <installation version="1.0">
  3. <info>
  4. <appname>Aria Installation</appname>
  5. <appversion>1.0</appversion>
  6. <authors>
  7. <author name="Joe Bloggs" email="joe.bloggs@mydomain.org"/>
  8. </authors>
  9. <url>http://www.mydomain.net/</url>
  10. </info>
  11.  
  12. <guiprefs width="640" height="480" resizable="no"/>
  13.  
  14. <locale>
  15. <langpack iso3="eng"/>
  16. </locale>
  17.  
  18. <resources>
  19. <res id="LicencePanel.licence" src="Licence.txt"/>
  20. <res id="InfoPanel.info" src="Readme.txt"/>
  21. <res id="shortcutSpec.xml" src="shortcutSpec.xml"/>
  22. </resources>
  23.  
  24. <native type="izpack" name="ShellLink.dll"/>
  25.  
  26. <panels>
  27. <panel classname="HelloPanel"/>
  28. <panel classname="InfoPanel"/>
  29. <panel classname="LicencePanel"/>
  30. <panel classname="TargetPanel"/>
  31. <panel classname="PacksPanel"/>
  32. <panel classname="InstallPanel"/>
  33. <panel classname="ShortcutPanel"/>
  34. <panel classname="FinishPanel"/>
  35. </panels>
  36.  
  37. <packs>
  38. <pack name="Base" required="yes">
  39. <description>The base files</description>
  40. <file src="Licence.txt" targetdir="$INSTALL_PATH"/>
  41. <file src="../bundle.jar" targetdir="$INSTALL_PATH"/>
  42. </pack>
  43. </packs>
  44. </installation>
  45.  

The info section of the file contains some basic information about the application being deployed. The guiprefs section will specify the size of the installation application. The locale can be modified to handle multiple languages.

The panels section specifies the screens which will make up the installation application. If there is a licence file for the application it can be specified here otherwise the LicencePanel node can be removed. Similarly, the InfoPanel displays a readmed for the application you are installing and can be removed if not appropriate.

Now all that is left to do is to create the installation jar file. This is done by creating a batch file in the izPack directory as follows:

Create the installation jar file

  1. "c:\Programmer\izpack\bin\compile" install.xml -b . -o install.jar -k standard

When run, the batch file will create the install.jar file. When double-clicked this file will start the installation script.

This jar file will only run if the Java runtime is installed on the machine. It is possible to automate the installation of the Java runtime by downloading the izpack-launcher-1.1.zip from the izforge website. All that is required then is to copy the dist/launcher-Win32.exe and the src/launcher.ini files to the izPack directory. The launcher.ini file is then modified to reflect the name of the installation jar.

The modified Launcher.ini file

  1. # Global entries, can be overriden by specific ones.
  2. jar = install.jar
  3. download = http://www.java.com/
  4.  
  5. # Win32 specific entries
  6. [win32]
  7. jre = jre/setup.exe

The download key specifies the source from which the Java runtime can be obtained in the event that it cannot be found on the system

The jre key specifies the subdirectory which contains the Java runtime which has been distributed with the setup. This setup for the Java runtime would typically be included when a CD installation is being distributed.