Deploy Netbeans Platform based Application using IzPack Installer

January 2nd, 2008 | by Tonny Kohar |

So, you just finished creating Netbeans Platform based Application and ready to deploy it to the users. You might be interested to check IzPack Installer.

IzPack is an installers generator for the Java platform. It produces lightweight installers that can be run on any operating system where a Java virtual machine is available. Depending on the operating system, it can be launched by a double-click or a simple java -jar installer.jar from a shell. The most common use is to distribute applications for the Java platform, but you can also use it for other kinds of projects.

This is what we used in Sketsa SVG Editor and Citra FX Photo Effects. Just change the values in the example below to fit your needs.

Note: this is tested on Netbeans 6 and 5.5

Update: this is based on the following folder/file structure

[your-suite-project-folder]
    - [branding]
    - [installer]
        - [icons]
        - [izpack]
            - izpack-install-script.xml
            - Win-shortcutSpec.xml
            - etc (other required izpack resources
                    eg: image, executable file, etc)
        - readme.html
    - [legal]
    - [nbproject]

Create IzPack Install script

First, you need to create IzPack install script and named it izpack-install-script.xml, similar like below:

<installation version="1.0">
 
    <!--
        The info section.
        The meaning of the tags should be natural ...
    -->
    <info>
        <appname>$APP-NAME</appname>
        <appversion>$APP-VERSION</appversion>
        <appsubpath>$APP-PATH</appsubpath> 
        <url>http://www.kiyut.com</url>
        <authors>
            <author email="support@kiyut.com" name="Kiyut Software"/>
        </authors>
        <uninstaller>yes</uninstaller>
        <javaversion>1.5</javaversion>
    </info>
 
 
    <variables>
        <variable name="JVM_REQ" value="Java VM (JRE) 1.5 or higher"/>
        <variable name="DesktopShortcutCheckboxEnabled" value="true"/>
    </variables>
 
 
    <!--
        The gui preferences indication.
        Sets the installer window to 640x480. It will not be able to change the size.
    -->
    <guiprefs width="640" height="480" resizable="no">
        <modifier key="useButtonIcons" value="no"/>
        <modifier key="useLabelIcons" value="no"/>
        <modifier key="allYGap" value="3"/>
        <modifier key="layoutAnchor" value="NORTHWEST"/>    
        <modifier key="useHeadingPanel" value="yes"/>
        <modifier key="headingLineCount" value="1"/>
        <modifier key="headingFontSize" value="1.5"/>
        <modifier key="headingBackgroundColor" value="0x00ffffff"/>
        <modifier key="headingPanelCounter" value="text"/>
        <modifier key="headingPanelCounterPos" value="inHeading"/>
    </guiprefs>
 
    <!--
        The locale section.
        Asks here to include the English and French langpacks.
    -->
    <locale>
        <langpack iso3="eng"/>
    </locale>
 
    <!--
        The resources section.
        The ids must be these ones if you want to use the LicencePanel and/or the InfoPanel.
    -->
    <resources>
        <res id="LicencePanel.licence" src="legal/LICENSE-sketsa.txt"/>
        <res id="shortcutSpec.xml" src="Win-shortcutSpec.xml"/>
        <res id="Unix_shortcutSpec.xml" src="Unix-shortcutSpec.xml"/>
        <res id="Installer.image" src="installer-image.png"/>
        <res id="XInfoPanel.info" src="XInfoPanel.txt"/>
        <res id="Heading.image" src="heading-image.png"/>
    </resources>
 
    <!-- The native libraries to add -->
    <native type="izpack" name="ShellLink.dll"/>
 
    <!--
        The panels section.
        We indicate here which panels we want to use. The order will be respected.
    -->
    <panels>
        <panel classname="HelloPanel"/>
        <panel classname="LicencePanel"/>
        <panel classname="PacksPanel"/>
        <panel classname="TargetPanel"/>
        <panel classname="InstallPanel"/>
        <panel classname="ShortcutPanel"/>
        <panel classname="XInfoPanel"/>
        <!-- <panel classname="FinishPanel"/> -->
        <panel classname="SimpleFinishPanel"/>
    </panels>
 
    <!--
        The packs section.
        We specify here our packs.
    -->
    <packs>
        <pack name="$APP-NAME" required="yes">
            <description>Core Files</description>
            <file targetdir="$INSTALL_PATH" src="bin" override="true" />
            <file targetdir="$INSTALL_PATH" src="etc" override="true" />
            <file targetdir="$INSTALL_PATH" src="harness" override="true" />
            <file targetdir="$INSTALL_PATH" src="ide8" override="true" />
            <file targetdir="$INSTALL_PATH" src="legal" override="true" />
            <file targetdir="$INSTALL_PATH" src="platform7" override="true" />
            <file targetdir="$INSTALL_PATH" src="sketsa" override="true" />
            <file targetdir="$INSTALL_PATH" src="readme.html" override="true" />
            <file targetdir="$INSTALL_PATH/Uninstaller" src="uninstaller.exe" override="true" />
            <file targetdir="$INSTALL_PATH/Uninstaller" src="uninstaller" override="true" />
            <executable targetfile="$INSTALL_PATH/bin/sketsa" stage="never"/>
            <executable targetfile="$INSTALL_PATH/Uninstaller/uninstaller" stage="never"/>
        </pack>
    </packs>
</installation>

For Microsoft Windows Shorcut, create the following file Win-shortcutSpec.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 
<shortcuts>
    <skipIfNotSupported/>
    <programGroup defaultName="Sketsa $APP-VERSION" location="applications"/>
 
    <shortcut
        name="Sketsa $APP-VERSION"
        programGroup="yes"
        desktop="yes"
        applications="no"
        startMenu="no"
        startup="no"
        target="$INSTALL_PATH\bin\sketsa.exe"
        commandLine=""
        description="Sketsa launcher"
        iconFile="$INSTALL_PATH\sketsa\sketsa.ico"
        iconIndex="0"
        initialState="noShow">
    </shortcut>
 
    <shortcut
        name="Readme.html"
        programGroup="yes"
        desktop="no"
        applications="no"
        startMenu="no"
        startup="no"
        target="$INSTALL_PATH\readme.html"
        commandLine=""
        description="Sketsa Readme">
    </shortcut>
 
    <shortcut
        name="Uninstaller"
        programGroup="yes"
        desktop="no"
        applications="no"
        startMenu="no"
        startup="no"
        target="$INSTALL_PATH\Uninstaller\uninstaller.exe"
        commandLine=""
        description="Sketsa uninstaller">
    </shortcut>
 
</shortcuts>

Finally add custom ant target in your suite build.xml

This target basically

  • build-zip distribution as specified in Netbeans Harness
  • unzip the result from the above build-zip
  • create the Izpack Installer from the above
  • zip the result again

You may also need the following properties defined in the suite Project Properties

# Custom Properties
# NOTE: Please check platform harness to avoid properties name conflict
app.title.full=${app.title} SVG Editor
app.buildnumber=200712311131
app.version=5.0.4
app.version.dash=5_0_4

Add the following ant target into your suite build.xml

<target name="build-installer" description="Create Installer" depends="clean,build-zip">
    <echo message=" "/>
    <echo message="Setting property and task for installer creation" />
    <property name="nbdist.dir" value="dist"/>
    <property name="nbdist-app.dir" value="${nbdist.dir}/${app.name}"/>
    <property name="nbdist-app-installer" value="${app.name}-${app.version.dash}.zip"/>
    <property name="izpack-installer" value="setup.jar"/>
    <property name="izpack.dir" value="/home/tonny/opt/IzPack"/>
    <taskdef name="izpack" classpath="${izpack.dir}/lib/compiler.jar" 
             classname="com.izforge.izpack.ant.IzPackTask"/>
 
    <echo message=" "/>
    <echo message="Preparing ...." />
 
    <unzip src="${nbdist.dir}/${app.name}.zip" dest="${nbdist.dir}"/>
 
    <copy todir="${nbdist-app.dir}/legal">
        <fileset dir="legal"/>
    </copy>
 
    <copy todir="${nbdist-app.dir}/${app.name}">
        <fileset dir="installer/icons" />
    </copy>
 
    <copy file="installer/readme.html" todir="${nbdist-app.dir}"/>
    <replace file="${nbdist-app.dir}/readme.html">
        <replacefilter token="$${app.version}" value="${app.version}" />
    </replace>
 
    <copy todir="${nbdist-app.dir}">
        <fileset dir="installer/izpack" />
    </copy>
    <replace file="${nbdist-app.dir}/izpack-install-script.xml">
        <replacefilter token="$APP-NAME" value="${app.title.full}" />
        <replacefilter token="$APP-VERSION" value="${app.version}" />
        <replacefilter token="$APP-PATH" value="Kiyut/${app.title}-${app.version.dash}" />
    </replace>
    <replace file="${nbdist-app.dir}/Win-shortcutSpec.xml">
        <replacefilter token="$APP-VERSION" value="${app.version}" />
    </replace>
    <replace file="${nbdist-app.dir}/etc/${app.name}.conf">
        <replacefilter token="/dev" value="/${app.version}" />
        <replacefilter token="-J-Xms24m -J-Xmx64m" value="${run.args.extra}" />
    </replace>
 
    <echo message=" "/>
    <echo message="Makes the installer using IzPack to ${izpack-installer}"/>
    <izpack input="${basedir}/${nbdist-app.dir}/izpack-install-script.xml"
            output="${basedir}/${nbdist-app.dir}/${izpack-installer}"  
            installerType="standard"              
            basedir="${basedir}/${nbdist-app.dir}"
            izPackDir="${izpack.dir}/"/>
 
    <echo message=" "/>
    <echo message="create the release ${nbdist-app-installer}"/>
    <zip destfile="${nbdist.dir}/${nbdist-app-installer}">
        <zipfileset dir="${nbdist-app.dir}">
            <include name="readme.html"/>
            <include name="setup.exe"/>
            <include name="${izpack-installer}"/>
        </zipfileset>
        <zipfileset dir="${nbdist-app.dir}" filemode="755">
            <include name="setup"/>
        </zipfileset>
    </zip>
 
    <echo message=" "/>
    <echo message="cleaning and finalizing release" />
    <delete dir="${nbdist-app.dir}"/>
 
    <echo message=" "/>
    <echo message="release: ${nbdist-app-installer}" />
 
</target>

Finally

It is done, just do not forget to test the result

Tags: , , , , , ,

  1. 20 Responses to “Deploy Netbeans Platform based Application using IzPack Installer”

  2. By Markus on Jan 2, 2008 | Reply

    IZPack is great for Windows and Linux and we use it for our platform application, http://www.nspike.com. I do wish they would include better support for MacOS X too.

  3. By Toni Epple on Jan 4, 2008 | Reply

    Hey Tonny, I wrote a tutorial on integrating IzPack with NetBeans on my blog a while ago myself. That reminds me tat I have to try out the openInstaller tutorial by Vadiraj.
    Toni

  4. By Tonny Kohar on Jan 4, 2008 | Reply

    @Toni Epple

    the more tutorial the better :)
    Yup, the OpenInstaller is seem very good options also. There is also Nbi installer from Netbeans

  5. By Tonny Kohar on Jan 4, 2008 | Reply

    @Markus

    Yes, it would be better if IzPack has support for Mac OSX. However, if your application is based on Netbeans Platform RCP, since Nb 6 there is already ant target for building Mac OSX

  6. By Kevin on Apr 18, 2008 | Reply

    What would help when using these instructions as a starting point is a folder layout, i.e. what folders are needed, what files go in what folders etc. For example, you say create izpack-install-script.xml but it’s not clear where you need to create this file until you start digging into the ant script. Describing the folder/file layout explicitly might make it easier for the reader to get up to speed.

  7. By Tonny Kohar on Apr 18, 2008 | Reply

    @Kevin

    Thanks for the feedback, I just updated the blog entry and add the folder/file structure layout

  8. By Kevin on Apr 18, 2008 | Reply

    One problem I had in following this example was with the uninstaller. The IzPack install script seems to assume uninstaller.exe exists, but where has this executable come from?

  9. By Tonny Kohar on Apr 18, 2008 | Reply

    @Kevin

    The uninstaller.exe is just a simple exe that execute uninstaller.jar. You can replace the uninstaller.exe with uninstaller.jar in the Win-shortcutSpec.xml uninstaller section

  10. By sushant on Aug 11, 2009 | Reply

    Hi.
    Your blog is really useful.Thanks.
    I was just curious to know, can we include other executables, like Mysql setup and put a condition
    on it, so that if mysql installation executes successfully, continue else break setup ?

  11. By Tonny Kohar on Aug 12, 2009 | Reply

    @sushant

    note: I haven’t tried yet, so it may or may not works.

    As far as I know, IzPack is very flexible installer. Please check the IzPack documentation regarding already build in conditional.

    Or in the worst case if there is no conditional as default, you can extends the IzPack (IzPack allow to be extended using Java) in the each step. Just write simple java run process which install MySQL or etc, and wrap it inside the IzPack.

  12. By pawloch on Sep 14, 2009 | Reply

    is there a way of creating updates with izpack ?

  13. By Tonny Kohar on Sep 14, 2009 | Reply

    @pawloch

    If you are using Netbeans Platform, you can deliver the update using nbm as specified by Netbeans Platform rather than using IzPack. IzPack is only used for base install only. After that the update will be delivered using nbm

  14. By superhomem on Mar 17, 2011 | Reply

    I followed the tutorial without success. I got the following error when I tried to build it.
    I am using Netbeans 6.9.1 on windows and I am new to the Ant scripting.

    Target “build-zip” does not exist in the project “MyProject”. It is used from target “build-installer”.
    BUILD FAILED (total time: 0 seconds)

    Any suggestions will be welcome

  15. By Tonny Kohar on Mar 18, 2011 | Reply

    @superhomem

    This tutorial is for Netbeans Platform based application, it is not for generic Java application.

  16. By superhomem on Mar 18, 2011 | Reply

    Sorry for not being more specific in my first post.
    It is indeed a Java Desktop Application that is based on the Simple DB (CRUD) App structure. It contains RxTx (JavaComm) and an Embedded Java DB, FYI.

    However as there is a request for a multiplatform easy installer I would welcome any suggestions or tutorials based on IzPack.

    Thanks for the clarification

  17. By Gun Trust Lawyer on Aug 12, 2013 | Reply

    I wanted to know if there was a way to convert the existing Netbeans projects into an installable .exe file so that it can be installed and used standalone?

  18. By Attorney San Antonio on Oct 11, 2013 | Reply

    Wow! This post is a seven-course meal! Many many thanks. I’m going to work on some of specific tools/tips you offer here.

  1. 3 Trackback(s)

  2. May 21, 2008: deploy application in netbeans
  3. Oct 6, 2012: Twitter Tool
  4. Sep 29, 2013: Instagram Marketing Tool

Post a Comment

*