powered by Jive Software

Using Izpack to create an installer with Ant

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”:

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

    <IzPack input="${basedir}/build/installer/spark-izpack.xml" output="${basedir}/installer/spark-installer.jar"
            installerType="standard" izPackDir="${installer.izpack.dir}" basedir="${basedir}"/>
           
    <taskdef name="launch4j"
            classpath="${installer.launch4j.dir}/launch4j.jar:${installer.launch4j.dir}/lib /xstream.jar"
            classname="net.sf.launch4j.ant.Launch4jTask"/>
           
    <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" ?> Spark 2.6.0 http://www.igniterealtime.org
<guiprefs width="640" height="480" resizable="no" />
<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>       

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" ?>
<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">
<shortcut
        name="Spark-@ver@ 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="This uninstalls Spark @build.number@">
    <createForPack name="Spark"/>
</shortcut>

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:

false gui c:\path\to\Spark\installer\spark.jar \path\where\you\want\the\spark.exe Spark . normal [http://java.com/download](http://java.com/download) false true \path\to\spark.ico -Dappdir="" ./jre/ 1.6.0_10 jdkOnly 2.6.1.0 2.6.1 Spark Your Company Inc. 2.6.1.0 2.0 Spark Your Company Chat Client Spark.exe An error occurred while starting the application. This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted. This application requires a Java Runtime Environment.\nAt least version The registry refers to a nonexistent Java Runtime Environment installation or the runtime is corrupted. An application instance is already running.

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

Our experience with jsmooth is not as good as with launch4j. Here are our results:

Wow thanks for that, I got an exe of the installer working in minutes. I will add my xml file to the doc above when I figure out how to get this to run from ant. If that’s possible.

I

Hi,

I have updated my latest izpack patch!

http://www.igniterealtime.org/community/message/188636#188636

I have updated with the new changes based on your new patch. I think its got everything now. It works perfectly for me now with the exception of the shortcuts, but I hope to have that done tonight.

Let me know if I left anything out.

Hi Jason,

I have see a Bug in your shurtcut.xml

Change this line:

to:

Thanks for that. I fixed above, but I believe I have already changed that in my copy and it still didn’t work. I will try it again and let you know.

Ok, I edited one more time to add to the spark-izpack.xml file. This is why my shortcuts were not working.

I think it’s done now. Mine compiles, builds the installer, and wraps it in an exe all with one command.

This is going to make my life so much better, i can have a custom spark client for anything now.

Dear Jason,

i have followed all the steps above but unfortunately i couldn’t get it work: First i tested it with Install4J demo version and it could compile successfully.

First it gave me error avac: invalid target release: 1.6 , so i changed it to 1.5 as i am using jre 1.5.0_06

i also changed the line 1.5.0_06 in spark.xml to match my jre version

and then when i compile i get too many errors like

build:
[javac] Compiling 46 source files to D:\Installers\Jive Software\Spark\target\classes
[javac] D:\Installers\Jive Software\Spark\src\java\org\jivesoftware\spark\filetransfer\SparkTransferManage r.java:17: cannot find symbol
[javac] symbol : class Desktop
[javac] location: package java.awt
[javac] import java.awt.Desktop;

[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 26 errors

please help me how can i fix them.

best regards

Hi,

I too tried as per your suggestion and the build got failed. Here is the exception am getting while running “ant installer.izpack”. Please help me.

E:\Prawin Share\spark_2_5_8\build>ant installer.izpack
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml

init:

resources:

base:
[jar] Building jar: E:\Prawin Share\spark_2_5_8\target\build\lib\base.jar

build:

jar:
[jar] Building jar: E:\Prawin Share\spark_2_5_8\target\build\lib\startup.j
ar
[jar] Building jar: E:\Prawin Share\spark_2_5_8\target\build\lib\spark.jar

installer.izpack:
[IzPack] Building installer jar: E:\Prawin Share\spark_2_5_8\installer\spark-
installer.jar
[IzPack] Copying 55 files into installer
[IzPack] Merging 5 jars into installer
[IzPack] Writing 1 Pack into installer

BUILD FAILED
java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/HierarchicalStreamDr
iver

Total time: 52 seconds
E:\Prawin Share\spark_2_5_8\build>

Thanks and Regards,

Praveen.

Can u plz give the full build.xml? Let me compare it.

Thanks and Regards,

Praveen

Praveen your problem can be fixed by downloading tools.jar from sun website, i do not know exact link but i am sure u can search and find it. i had in my jdeveloper jdk folder, so i copied it from there to jre.

i could have uploaded it but i do not see any option to upload a file.

i can send it by email if you do not find it on google.

finally if you succeed to compile then kindly send me all the files explained in the document to compile spark with izpack

with sincere regards

mazhar

Hi Mazhar,

Thanks for your reply. Thank god. The problem is not with the jar file. The problem is with the path in the build.xml. Today I have successfully compiled and created the exe file and is working fine. The only problem is the DOS prompt also gets displayed while executing. Do someone help me how to hide the DOS prompt while executing the Spark.

Thanks for all the support from all the members. Special thanks to cstux.

Thanks and Regards,

Praveen.

Dear Praveen,

i sent you a private message with my email address. its a good news that finally you succeeded. i will really appreciate if you can send me the steps you compiled. as you know i have tried following the doc above but with lot of java compile time erros, things like deprecated methods and override exceptions.

BR

mazhar

ok my bad. the issue with previous errors was that i had not JAVA_HOME variable defined.

After i defined the variable, i had no more those javac errors.

But now i am stuck at the following error.

please help

installer.izpack:
[IzPack] Building installer jar: D:\Installers\Jive Software\spark-svn\Spark\installer\spark-installer.jar
[IzPack] Copying 55 files into installer
[IzPack] Merging 5 jars into installer
[IzPack] Writing 1 Pack into installer

BUILD FAILED
D:\Installers\Jive Software\spark-svn\Spark\build\build.xml:419: net.sf.launch4j.BuilderException: Application jar doesn’t exist.

best regards

mazhar

ok Success.

I finally succeeded.

i changed

from D:\Installers\Jive Software\spark.jar

to

D:\Installers\Jive Software\spark-svn\Spark\installer\spark-installer.jar

in the spark.xml

and it compiled it successfully

thank you all for the help.

BR

mazhar

hi praveen,

ok in my private message where is said changing the target to startup.jar , has one problem that it will not startup the plugins. So better do it this way

simply change target to startup.bat -noconsole

in the shortcutSpec.xml

i.e.

target="$INSTALL_PATH\lib\startup.bat -noconsole"

and there will be no dos window anymore

thanks again to everybody here, espectially to cstux for the document.

i am sorry guys, actually i was mistaken in my previous post.

using target="$INSTALL_PATH\lib\startup.bat -noconsole" will cause windows no target found short issue.

and if you do

target="$INSTALL_PATH\bin\startup.bat" -noconsole

the installer will not install the shortcusts.

so it will be great if someone can comment.

Finally,

adding

commandLine="-noconsole"

to shortcutSpec.xml

does the trick

Dear Mazhar,

Adding tht works. But we want to manually close the command prompt. But it should not get displayed.** ** I too will try some alternatives. If u find, plz update me.

Thanks and Regards,

Praveen.