# Using Izpack to create an installer with Ant

Version 6

I have been compiling custom spark versions for about two years to use at work. We have a large windows network and the worst part has always been creating an exe or msi to push the new versions out to our users. I have tried using various open source install builders and trial versions of commercial builders with mixed success. None of the commercial products I have tried have been easy or automatable enough to get me to fork out the usually hundreds of dollars they seem to think these products are worth. This has often caused me to procrastinate about adding features I might want or even just keeping up to date with the latest version.

Recently we had some major changes and I just could not put off compiling a new version anymore. I downloaded the latest source from SVN and made the changes I wanted and compiled. Easy as pie, it only took about four hours for everything, including updating my version of ant and getting the latest java sdk.

Then It was time to figure out what to do about the installer. I came to the forums and couldnt find any new ideas, except for this post from cstux about Izpack which I had never heard of. His patch is apparently for Eclipse which I have never used so at first I was a little stumped. But after some digging around and several dead ends I was finally able to use his patch and his tip about "ant installer.izpack" to finally compile and get an installer in one easy step.

This is still a work in progress so any tips or suggestions are greatly appreciated.

Step 1. Download and Install izpack ( http://izpack.org/ ) and launch4j ( http://launch4j.sourceforge.net/ )

Step 2. Open up your build.xml file and make the following changes:

Under the rest of the property tags near the top of the file add this line changing "path/to/Izpack" to match your system. In my case it was "c:\\Program Files\\izpack":

<property name="installer.izpack.dir" value="/path/to/IzPack/"/>

<property name="installer.launch4j.dir" value="c:\\Program Files\\Launch4j" />

Then directly under the comment where the installers start I added :

<target name="installer.izpack" depends="jar" description="build release a izpack installer">
<mkdir dir="${basedir}/installer/" /> <taskdef name="IzPack" classpath="${installer.izpack.dir}/lib/standalone-compiler.jar"

<IzPack input="${basedir}/build/installer/spark-izpack.xml" output="${basedir}/installer/spark-installer.jar"
installerType="standard" izPackDir="${installer.izpack.dir}" basedir="${basedir}"/>

classpath="${installer.launch4j.dir}/launch4j.jar:${installer.launch4j.dir}/lib /xstream.jar"

<launch4j configFile="${basedir}/build/installer/spark.xml" tmpdir="c:\tmp" /> </target> Notice the c:\tmp, I got an error that said the temp director path can't ave spaces in it Step 3. Create a file under build/installer called spark-izpack.xml and paste this into it, be sure to change the references to spark and the ignite realtime website to match your version: <?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?> <installation version="1.0"> <info> <appname>Spark</appname> <appversion>2.6.0</appversion> <url>http://www.igniterealtime.org</url> </info> <guiprefs width="640" height="480" resizable="no" /> <native type="izpack" name="ShellLink.dll"/> <locale> <langpack iso3="eng"/> <langpack iso3="fra"/> <langpack iso3="deu"/> <langpack iso3="ita"/> <langpack iso3="jpn"/> <langpack iso3="spa"/> <langpack iso3="dan"/> <langpack iso3="ell"/> <langpack iso3="cat"/> <langpack iso3="ned"/> <langpack iso3="fin"/> <langpack iso3="swe"/> <langpack iso3="por"/> <langpack iso3="pol"/> <langpack iso3="rus"/> <langpack iso3="ukr"/> <langpack iso3="hun"/> <langpack iso3="svk"/> <langpack iso3="rom"/> <langpack iso3="mys"/> <langpack iso3="nor"/> <langpack iso3="chn"/> <langpack iso3="scg"/> <langpack iso3="cze"/> <langpack iso3="kor"/> <langpack iso3="glg"/> </locale> <resources> <res src="build/installer/izpack/shortcutSpec.xml" id="shortcutSpec.xml"/> </resources> <panels> <panel classname="TargetPanel" /> <panel classname="PacksPanel" /> <panel classname="InstallPanel" /> <panel classname="ShortcutPanel" /> <panel classname="FinishPanel" /> </panels> <packs> <pack name="Spark" required="yes"> <description>XMPP Client</description> <file src="target/build/bin" targetdir="$INSTALL_PATH"/>
<file src="target/build/lib"        targetdir="$INSTALL_PATH"/> <file src="target/build/logs" targetdir="$INSTALL_PATH"/>
<file src="target/build/plugins"    targetdir="$INSTALL_PATH"/> <file src="target/build/resources" targetdir="$INSTALL_PATH"/>
<file src="target/build/xtra"        targetdir="$INSTALL_PATH"/> <executable targetfile="$INSTALL_PATH/bin/startup.sh" />
<executable targetfile="$INSTALL_PATH/bin/startup.bat" /> </pack> </packs> </installation> You can customize this file a lot and there is very good documentation on the Izpack website. For instance if you remove all of the languages under locale except the one you want then the user will not see the language selector. Since I am going for as automated an install as possible I kept mine pretty brief and simple. Step 4: Create a folder in build/installer called izpack In that folder create a new file called shortcutSpec.xml and paste the following into it: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <shortcuts> <skipIfNotSupported/> <programGroup defaultName="Spark" location="applications"/> <shortcut name="IzPack" programGroup="yes" desktop="yes" applications="no" startMenu="no" startup="no" target="$INSTALL_PATH\bin\startup.bat"
commandLine=""
description="Spark"
iconIndex="0"
initialState="noShow">

<createForPack name="Spark"/>

</shortcut>

<shortcut
name="Spark-@ver@ Uninstaller"
programGroup="yes"
desktop="no"
applications="no"
startup="no"
target="\$INSTALL_PATH\Uninstaller\uninstaller.jar"
commandLine=""
iconFile="%SystemRoot%\system32\SHELL32.dll"
iconIndex="31"
description="This uninstalls Spark @build.number@">
<createForPack name="Spark"/>
</shortcut>

</shortcuts>

This lets you control where shortcuts will be places and what kind of Icons to display. I honestly haven't messed with this too much yet

but it seems to be pretty easy to figure out and I will add more if I find something interesting.

Step 5:

Create a file called spark.xml in build/installer and paste in the following:

<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<jar>c:\path\to\Spark\installer\spark.jar</jar>
<outfile>\path\where\you\want\the\spark.exe</outfile>
<errTitle>Spark</errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<supportUrl></supportUrl>
<customProcName>false</customProcName>
<stayAlive>true</stayAlive>
<manifest></manifest>
<icon>\path\to\spark.ico</icon>
<var>-Dappdir=&quot;&quot; </var>
<jre>
<path>./jre/</path>
<minVersion>1.6.0_10</minVersion>
<maxVersion></maxVersion>
<jdkPreference>jdkOnly</jdkPreference>
</jre>
<versionInfo>
<fileVersion>2.6.1.0</fileVersion>
<txtFileVersion>2.6.1</txtFileVersion>
<fileDescription>Spark</fileDescription>
<productVersion>2.6.1.0</productVersion>
<txtProductVersion>2.0</txtProductVersion>
<productName>Spark</productName>
<internalName>Chat Client</internalName>
<originalFilename>Spark.exe</originalFilename>
</versionInfo>
<messages>
<startupErr>An error occurred while starting the application.</startupErr>
<bundledJreErr>This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted.</bundledJreErr>
<jreVersionErr>This application requires a Java Runtime Environment.\nAt least version</jreVersionErr>
<launcherErr>The registry refers to a nonexistent Java Runtime Environment installation or the runtime is corrupted.</launcherErr>
</messages>
</launch4jConfig>

Step 6:

To compile run "ant installer.izpack" in the build directory. This will create your regular target directory and a new directory called installer. The installer.jar file will be in there. Its very fast so if you mess up and want to recompile until you get it right it is no big deal.

If anyone has any advice on making this document more understandable please let me know that as well.

Jason