Deploy your Java Application with IzPack Installer

Deploy your Java Application with IzPack Installer

This is a short tutorial on how to create simple IzPack based installation solution on windows platform with all standard features like: desktop shortcut, start menu item shortcut, copying libraries, folders, documentation into one of the ProgramFiles folder on the windows machine.
I had some problems creating windows shortcuts mysefl and I wanted to share the experience so other people can find it quicker.
Here you go.


1. First download and install IzPack itself from: izpack website

2. Prepare the application you want to make installable, I use Netbeans to build most of my Java apps, but I guess for all other ide’s the results after all are the same, we end up with SomeApp.jar file and a bunch of libraries we used to build it.
On the Netbeans platform all the files needed to launch the application we have build end up in ‘dist’ folder as a subfolder of our project main folder. If you have used any libraries to build your desktop application they will be included in the lib folder (yourproject/dist/lib/).

3. Now, once we have all the main ingredients (our application and installer) we need to connect it together. Create the folder anywhere on your machine, and call it for example ‘softwarepassion’.

4. Put your jar file together with the ‘lib’ folder into the ‘softwarepassion’ catalog.

5. Now we need to add some native libraries for Izpack to be able to add windows shortcuts on the desktop and start menu. Create ‘bin’ folder under the ‘softwarepassion’ folder and copy whole ‘native’ content found in your izpack installation into the ‘bin’ folder of your root ‘softwarepassion’ catalog.
You can find the native folder inside your IzPack installation directory, normally under: ‘C:\Program Files\IzPack\bin’

6. Create your application icon file and add it to your ‘softwarepasison’ catalog. I call mine ‘exe.ico’.

7. Now comes the hardest part to get initially but after you build your first installer it all gets clear and easy ๐Ÿ™‚
We need to prepare two separate xml files: one called ‘install.xml’ and another one called ‘shortcutSpec.xml’.

The content of both example files is listed below:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>

<!--
   A sample installation file.
   Use it as a base for your own installers :-)
   
   To compile it :
   - go in the bin directory where you installed IzPack
   - call "compile ../sample/install.xml -b ../sample"
-->

<installation version="1.0">

    <!--
       The info section.
       The meaning of the tags should be natural ...
   -->
    <info>
        <appname>SoftwarePassion Application</appname>
        <appversion>1.0</appversion>
        <authors>
            <author name="Softberries Krzysztof Grajek" email="customer.service@softberries.com"/>
        </authors>
        <url>http://www.softwarepassion.com/</url>
    </info>

    <!--
       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="yes"/>
    <variables>
        <variable name="DesktopShortcutCheckboxEnabled" value="true"/>
    </variables>
    <!--
       The locale section.
       Asks here to include the English and French langpacks.
   -->
    <locale>
        <langpack iso3="pol"/>
        <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 src="shortcutSpec.xml" id="shortcutSpec.xml"/>
        <res id="LicencePanel.licence" src="Licence.txt"/>
        <res id="InfoPanel.info" src="Readme.txt"/>
    </resources>

    <!--
       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="TargetPanel"/>
        <panel classname="PacksPanel"/>
        <panel classname="InstallPanel"/>
        <panel classname="ShortcutPanel"/>
        <panel classname="FinishPanel"/>
    </panels>

    <!--
       The packs section.
       We specify here our packs.
   -->
    <packs>
        <pack name="Base" required="yes">
            <description>The base files</description>
            <file src="Readme.txt" targetdir="$INSTALL_PATH"/>
            <file src="Licence.txt" targetdir="$INSTALL_PATH"/>
            <file src="exe.ico" targetdir="$INSTALL_PATH"/>
            <file src="SoftwarePassionHelloIzPack.jar" targetdir="$INSTALL_PATH"/>
            <fileset dir="lib" targetdir="$INSTALL_PATH\lib">
                <include name="**"/>
            </fileset>
        </pack>
    </packs>
    <native type="izpack" name="ShellLink.dll"/>
    <native type="3rdparty" name="COIOSHelper.dll" stage="both">
        <os family="windows"/>
    </native>
</installation>

And the one for windows shortcuts:

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

<shortcuts>

    <skipIfNotSupported/>

    <programGroup defaultName="Siemens AWORT" location="applications"/>

      <shortcut
         name="SoftwarePassion Application"
         programGroup="yes"
         desktop="yes"
         applications="no"
         startMenu="yes"
         startup="no"
         target="$INSTALL_PATH\SoftwarePassionHelloIzPack.jar"
         commandLine=""
         description="Software Passion Example App"
         iconFile="$INSTALL_PATH\exe.ico"
         iconIndex="0"
         initialState="noShow">

         <createForPack name="Base"/>

       </shortcut>
 

    <shortcut
            name="Software Passion Example App Uninstaller"
            programGroup="yes"
            desktop="no"
            applications="no"
            startMenu="no"
            startup="no"
            target="$INSTALL_PATH\Uninstaller\uninstaller.jar"
            commandLine=""
            iconFile="%SystemRoot%\system32\SHELL32.dll"
            iconIndex="31"
            description="Uninstall SoftwarePassion Example">

        <createForPack name="Base"/>
    </shortcut>

</shortcuts>

8. Example installation script contains both Readme.txt and Licence.txt which you can add to your ‘softwarepassion’ folder.
9. Once you have it all in one place, you should have a structure like in the following screenshot:

izpack_directory

10. Now assuming that your ‘softwarepassion’ folder has been placed directly on the c: drive, execute the following command:

C:\Program Files\IzPack\bin>compile c:\softwarepassion\install.xml -b c:\softwarepassion

Assuming that IzPack itself was installed at: C:\Program Files\IzPack

This will produce install.jar file which is your installer.

11. If you dont’ want your end users to click on the ‘jar’ file as not everybody knows they can do that, you can add Izpack launcher app which will launch it automatically, or use another tool to create an executable called launch4j

You have to admit that it was an easy one!!!!!

Happy Installing!


Download example files from here

21 responses on “Deploy your Java Application with IzPack Installer

  1. Dan Powell March 9, 2010 at 12:58 pm

    Well written article, Krzysztof.

    I think you’re right that writing xml by hand is the “hardest part”. It’s too error prone and seems seems primitive. Why choose a java installer builder that makes you do that? You use Netbeans instead of the java command line tools.

    Dan

  2. poonam March 12, 2010 at 7:24 am

    I have followed whole steps.My installer has created but shortcut is not created and also my application jar file is not included in the folder which is created after installation of application.

    Thanks…

  3. admin March 12, 2010 at 12:16 pm

    Please double check your install.xml, especially the part with ‘packs’ where all the files to be copied are declared.

  4. Happy Reader April 12, 2010 at 12:12 am

    Much Thanks! I’ve been trying to get the ShortCutPanel to work for some time….:( With your article (sample app) as a reference point I could see how the directory structure should look. Much appreciated.

  5. Issac Varghese April 13, 2010 at 6:40 am

    Hi,

    I followed your steps and got everything which I wanted. The installer created the Shortcut on the Desktop. When I clicked on the Shortcut, it ran the Software.

    But the only issue is, the files being created by my software are getting created on the Desktop, rather, it should have been created in the Installation Folder.

    How to overcome this problem?

    And how to create installers and Shortcuts for Linux and Mac OS?

    Thanks and Regards,

    Issac Varghese

  6. Sonali April 25, 2010 at 10:49 am

    I have been going through the izpack manual for days. But was helpless figuring out, how to compile the install.xml . You just save me another week’s worth of searching. Thanks a lot! This is the best tutorial about izpack! Thanks again!! It worked fine for me..

  7. jeet May 7, 2010 at 9:23 am

    Hi
    i have done all the work which you describe in the tutorial

    when i run that command i got following error and exception:

    ERROR: ‘Content is not allowed in prolog.’
    ERROR: ‘com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Content
    is not allowed in prolog.’

    please reply if any one have some suggestion

  8. elz May 21, 2010 at 5:54 am

    Please can you add how to add the native luancher to check if jre is installed in the system. thnx a bunch..:)

  9. Patrick Fidler August 21, 2010 at 4:09 am

    First class piece of work, excellent tutorial. Many thanks.

  10. Vishwas Babu January 29, 2011 at 1:07 am

    Excellent Post! Thanks ๐Ÿ™‚

  11. Pawan February 25, 2011 at 8:16 am

    Great example..thanks!

  12. Sรฉrgio Michels July 15, 2011 at 9:57 pm

    Thanks!!!!!

  13. Patrick Fidler August 4, 2011 at 4:48 am

    Very many thanks Krzysztof, a great piece of work.

  14. A Mando October 17, 2011 at 3:33 am

    Thank you very much, that was very helpful.
    Very much appreciated

  15. aparna February 9, 2012 at 7:37 am

    very helpful for 1st time users of Izpack

  16. kash___if July 5, 2013 at 8:16 am

    great !!!

  17. Jeramie Vargas August 15, 2013 at 5:22 am

    You rock!
    Thanks for the great article. ๐Ÿ™‚
    I was wondering what if I need to include an image to the package?

    Thanks again!

  18. Jeramie Vargas August 15, 2013 at 9:33 am

    Hey, one more. ShortcutPanel not working in win7.

  19. Renukeswar June 28, 2017 at 7:52 pm

    Getting this exception while compiling the install.xml
    java.lang.NullPointerException
    at com.izforge.izpack.util.IoHelper.copyStreamToJar(IoHelper.java:465)

Leave a Reply