为什么要先介绍install.xml这个文件呢,因为这个文件太重要了,地位犹如Ant中的build.xml,maven中的pom.xml。install.xml直接定义了安装包的界面、显示窗口、使用的类、语言等等。弄懂了install.xml,就可以很轻松的定制自己的安装程序。
<?xml version="1.0" encoding="utf-8" 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">
<!--
程序基本信息
-->
<info>
<appname>台站系统</appname>
<appversion>1.0</appversion>
<authors>
<author name="**" email=""/>
<author name="**" email=""/>
</authors>
<url>http://youkuaiyun.com</url>
<javaversion>1.6</javaversion>
</info>
<!--
安装程序窗口大小、字体大小、间距等设置
-->
<guiprefs width="640" height="480" resizable="no">
<laf name="looks">
<os family="windows" />
<param name="variant" value="windows" />
</laf>
<laf name="substance">
<os family="windows" />
<param name="variant" value="business-blue" />
</laf>
<modifier key="useButtonIcons" value="yes"/>
<modifier key="labelFontSize" value="1.5"></modifier>
<modifier key="layoutAnchor" value="CENTER"/>
<modifier key="useLabelIcons" value="yes"/>
<modifier key="useHeadingPanel" value="yes"/>
<modifier key="headingBackgroundColor" value="0x00ffffff"/>
<modifier key="headingPanelCounter" value="progressbar"/>
<modifier key="headingPanelCounterPos" value="inNavigationPanel"/>
<modifier key="allYGap" value="4"/>
<modifier key="paragraphYGap" value="10"/>
<modifier key="filler1YGap" value="5"/>
<modifier key="filler3XGap" value="10"/>
</guiprefs>
<!--
The locale section.
Asks here to include the English and French langpacks.
语言选项
-->
<locale>
<langpack iso3="chn"/>
</locale>
<!--
The resources section.
The ids must be these ones if you want to use the LicencePanel and/or the InfoPanel.
引入的资源
-->
<resources>
<res id="userInputSpec.xml" src="userInputSpec.xml"/>
<res id="ProcessPanel.Spec.xml" src="ProcessPanel.Spec.xml"/>
<res id="shortcutSpec.xml" src="shortcutSpec.xml"/>
</resources>
<!--
The panels section.
We indicate here which panels we want to use. The order will be respected.
需要哪些panel,panel就是窗口,列出的顺序也是显示的顺序
-->
<panels>
<panel classname="HelloPanel"/>
<panel classname="TargetPanel"/>
<panel classname="PacksPanel"/>
<panel classname="UserInputPanel" id="jdbc.parameters">
<validator classname="ConnectionValidation"/>
</panel>
<panel classname="InstallPanel"/>
<panel classname="UserInputPanel" id="station.parameters"/>
<panel classname="ProcessPanel"/>
<panel classname="ShortcutPanel"/>
<panel classname="FinishPanel"/>
</panels>
<!-- 设置常量 -->
<variables>
<variable name="InstallerFrame.logfilePath" value="$INSTALL_PATH/log/install.log" />
<variable name="DesktopShortcutCheckboxEnabled" value="true" />
</variables>
<!-- 引入自定义类和第三方jar -->
<jar src="station_test.jar" stage="install"/>
<jar src="jtds-1.2.4.jar" stage="install"/>
<jar src="ibatis2-common-2.1.7.597.jar" stage="install"/>
<!-- 引入本地类库,创建快捷方式时需要用到 -->
<native type="izpack" name="ShellLink.dll"/>
<native type="izpack" name="ShellLink_x64.dll"/>
<!--
The packs section.
We specify here our packs.
需要打包的文件或文件夹,以及打包的地址
-->
<packs>
<pack name="tomcat" required="yes">
<description>tomcat server</description>
<file src="../tomcat7" targetdir="$INSTALL_PATH"/>
<!-- The file will be parsed -->
</pack>
<pack name="station" required="yes">
<description>station</description>
<file src="../station" targetdir="$INSTALL_PATH"/>
<!-- Reccursive adding -->
</pack>
</packs>
</installation>
上面是一个install.xml文件一个例子,其中添加了一些注释,下面详细讲一下各个标签的使用和作用:
- info标签:这个标签里包含了很多子标签,主要描述被安装的程序的基本信息,比如作者、使用的java版本等等,这些信息会展示在HelloPanel这个面板上
- guiprefs标签:这个标签里定义了安装程序窗口的大小、字体大小、各个面板上标签之间的X和Y方向间距、进度条的展示、按钮图片、窗口颜色等等
- locale标签:这个标签主要用于国际化,可以定义很多语言,供用户选择
- resources标签:这个标签主要用来引入自己的自定义资源,比如用户协议文档、用户输入面板、自定义处理面板等等
- panels标签:这个标签很重要,也是接下来讲述的重点,也是我们最关心的,这个标签里面定义了很多panel,每个panel就是我们熟悉的安装程序中的一步,点击上一步或者下一步可以跳到另一面板,因此这里定义的panel有顺序性,第一个panel标签就是安装程序第一个面板。IzPack提供了很多panel,有很多可以直接使用,像HelloPanel,有些需要自定义,比如UserInputPanel,我们的主要任务就是根据自己的需求,引入不同的panel,编写自己的panel。其实大家用的最多还是用户输入面板(UserInputPanel)和处理面板(ProcessPanel),后面会详细介绍这两个的使用
- packs标签:这里定义了安装程序需要把哪些文件安装到用户电脑中,每个pack标签都定义了一个安装任务,可以通过属性required来定义是否必须选择,或者由用户选择。上面例子中<file src="../station" targetdir="$INSTALL_PATH"/>这句话是关键,定义了需要把上级目录的station文件夹安装到用户指定的安装目录,其中$INSTALL_PATH就是指用户选择的安装目录。当编译这个安装包时,会把这些指定的文件或文件夹打包放在安装包中,当用户点击安装时,直接从安装包解压复制到安装目录,复制的操作是在InstallPanel这个面板出现时进行,因此缺少这个panel,将不会把文件安装到指定目录,并且要注意InstallPanel在所有panels中的位置,因为有时我们需要动态修改安装后的文件,要使用$INSTALL_PATH来访问安装后的文件,如果还没有到InstallPanel,那么安装目录里什么文件都没有,我们将无法访问。