Installation with IzPack — Launching BAT Files
Intuitively we know -- if we can run a bat file.. we can probably to everything. And yes, you can run bat files from IzPack too!
I will assume, that you read my previous post about simple IzPack + Maven applications. In order to run a bat file, we will have to use a IzPack ProcessPanel.
In your install.xml you need to add a resources, where you will specify a configuration of your bat file (where it exists and what parameters should be passed to it):
<resources> <res id="ProcessPanel.Spec.xml" src="processPanelSpec.xml" /> </resources>
Then, you will need to create a file named processPanelSpec.xml. If you run the example from my previous post, the location of this file should be src/main/resources. In this file you specify, what file needs to be run and what parameters should be passed to it:
<?xml version="1.0" encoding="UTF-8"?>
<processing>
<job name="Say Hello">
<executefile name="$INSTALL_PATH/sayHello.bat">
<env>name=Max</env>
</executefile>
</job>
</processing>
In two words, $INSTALL_PATH/sayHello.bat is location of our bat file -- we will cover this later. arg is passed argument.
Then in src/main/resources create a sayHello.bat file:
echo Hello %name%
And then in install.xml file in main pack (<packs><pack>..) say, that you want to include that bat file:
<packs>
<pack name="main" required="yes">
...
<file src="sayHello.bat" targetdir="$INSTALL_PATH" override="true" />
</pack>
</packs>
And in install.xml in panels you need to specify three panels. The first is either TargetPanel or DefaultTargetpanel which would tell IzPack where it is possible to extract installation filees. Another one is InstallPanel which tells when to unpack the installation files. And the last one is ProcessPanel which specifies when a file needs to be processed:
<panels> <panel classname="HelloPanel" /> <panel classname="TargetPanel" /> <panel classname="ProcessPanel" /> <panel classname="SimpleFinishPanel" /> </panels>
And then you can run mvn install. You will find your installer in standard target folder. And you should be able to see a message "Hello Max".
Here is a complete install.xml which I used for this example:
<?xml version="1.0" encoding="UTF-8"?>
<installation version="1.0">
<info>
<appname>test</appname>
<appversion>1</appversion>
<uninstaller write="no" />
<javaversion>1.6</javaversion>
<pack200 />
</info>
<guiprefs resizable="no" width="480" height="360">
<laf name="looks">
<param name="variant" value="windows" />
<os family="windows" />
</laf>
</guiprefs>
<locale>
<langpack iso3="eng" />
</locale>
<resources>
<res id="ProcessPanel.Spec.xml" src="processPanelSpec.xml" />
</resources>
<panels>
<panel classname="HelloPanel" />
<panel classname="TargetPanel" />
<panel classname="InstallPanel" />
<panel classname="ProcessPanel" />
<panel classname="SimpleFinishPanel" />
</panels>
<packs>
<pack name="main" required="yes">
<description>Test Installation</description>
<file src="sayHello.bat" targetdir="$INSTALL_PATH" override="true" />
</pack>
</packs>
</installation>
July 27th, 2010 - 13:11
Hi. good article! I’m cofiguring my installer in this way, but I have a warning during building and then the process panel isn’t found. Here is thу stacktrace:
Adding resource: IzPack.uninstaller
Setting the installer information
Setting the GUI preferences
Adding langpack: rus
Adding resource: flag.rus
Adding resource: ProcessPanelSpec.xml
Adding native library: ShellLink.dll
Adding native library: COIOSHelper.dll
Adding resource: IzPack.uninstaller-ext
Adding content of jar: file:/C:/Program%20Files/IzPack/lib/standalone-compiler.j
ar!/bin/panels/HelloPanel.jar
Adding content of jar: file:/C:/Program%20Files/IzPack/lib/standalone-compiler.j
ar!/bin/panels/TargetPanel.jar
Adding content of jar: file:/C:/Program%20Files/IzPack/lib/standalone-compiler.j
ar!/bin/panels/InstallPanel.jar
Warning: C:\java\installer\install.xml:32: Panel jar file not found: C:\Program
Files\IzPack\bin\..\bin\panels\null.jar
Adding content of jar: file:/C:/Program%20Files/IzPack/lib/standalone-compiler.j
ar!/bin/panels/FinishPanel.jar
Building installer jar: C:\java\installer\install.jar
Can you help me with it?
July 27th, 2010 - 16:52
Mhm.. strange. How do you include a
ProcessPanel? Can you paste yourinstall.xmlfile here?August 3rd, 2010 - 08:35
Hi, I was absent for several days… Today I reinstall IzPack and this warning disappeared. Sorry for the inconvenience.