【IzPack】使用----install.xml

前端之家收集整理的这篇文章主要介绍了【IzPack】使用----install.xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

为什么要先介绍install.xml这个文件呢,因为这个文件太重要了,地位犹如Ant中的build.xml,maven中的pom.xml。install.xml直接定义了安装包的界面、显示窗口、使用的类、语言等等。弄懂了install.xml,就可以很轻松的定制自己的安装程序。

  1. <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
  2.  
  3. <!--
  4. A sample installation file.
  5. Use it as a base for your own installers :-)
  6. To compile it :
  7. - go in the bin directory where you installed IzPack
  8. - call "compile ../sample/install.xml -b ../sample"
  9. -->
  10.  
  11. <installation version="1.0">
  12.  
  13. <!--
  14. 程序基本信息
  15. -->
  16. <info>
  17. <appname>台站系统</appname>
  18. <appversion>1.0</appversion>
  19. <authors>
  20. <author name="**" email=""/>
  21. <author name="**" email=""/>
  22. </authors>
  23. <url>http://csdn.net</url>
  24. <javaversion>1.6</javaversion>
  25. </info>
  26.  
  27. <!--
  28. 安装程序窗口大小、字体大小、间距等设置
  29. -->
  30. <guiprefs width="640" height="480" resizable="no">
  31. <laf name="looks">
  32. <os family="windows" />
  33. <param name="variant" value="windows" />
  34. </laf>
  35. <laf name="substance">
  36. <os family="windows" />
  37. <param name="variant" value="business-blue" />
  38. </laf>
  39. <modifier key="useButtonIcons" value="yes"/>
  40. <modifier key="labelFontSize" value="1.5"></modifier>
  41. <modifier key="layoutAnchor" value="CENTER"/>
  42. <modifier key="useLabelIcons" value="yes"/>
  43. <modifier key="useHeadingPanel" value="yes"/>
  44. <modifier key="headingBackgroundColor" value="0x00ffffff"/>
  45. <modifier key="headingPanelCounter" value="progressbar"/>
  46. <modifier key="headingPanelCounterPos" value="inNavigationPanel"/>
  47. <modifier key="allYGap" value="4"/>
  48. <modifier key="paragraphYGap" value="10"/>
  49. <modifier key="filler1YGap" value="5"/>
  50. <modifier key="filler3XGap" value="10"/>
  51.  
  52. </guiprefs>
  53.  
  54. <!--
  55. The locale section.
  56. Asks here to include the English and French langpacks.
  57. 语言选项
  58. -->
  59. <locale>
  60. <langpack iso3="chn"/>
  61. </locale>
  62.  
  63. <!--
  64. The resources section.
  65. The ids must be these ones if you want to use the LicencePanel and/or the InfoPanel.
  66. 引入的资源
  67. -->
  68. <resources>
  69. <res id="userInputSpec.xml" src="userInputSpec.xml"/>
  70. <res id="ProcessPanel.Spec.xml" src="ProcessPanel.Spec.xml"/>
  71. <res id="shortcutSpec.xml" src="shortcutSpec.xml"/>
  72. </resources>
  73.  
  74. <!--
  75. The panels section.
  76. We indicate here which panels we want to use. The order will be respected.
  77. 需要哪些panel,panel就是窗口,列出的顺序也是显示的顺序
  78. -->
  79. <panels>
  80. <panel classname="HelloPanel"/>
  81. <panel classname="TargetPanel"/>
  82. <panel classname="PacksPanel"/>
  83. <panel classname="UserInputPanel" id="jdbc.parameters">
  84. <validator classname="ConnectionValidation"/>
  85. </panel>
  86. <panel classname="InstallPanel"/>
  87. <panel classname="UserInputPanel" id="station.parameters"/>
  88. <panel classname="ProcessPanel"/>
  89. <panel classname="ShortcutPanel"/>
  90. <panel classname="FinishPanel"/>
  91. </panels>
  92. <!-- 设置常量 -->
  93. <variables>
  94. <variable name="InstallerFrame.logfilePath" value="$INSTALL_PATH/log/install.log" />
  95. <variable name="DesktopShortcutCheckBoxEnabled" value="true" />
  96. </variables>
  97. <!-- 引入自定义类和第三方jar -->
  98. <jar src="station_test.jar" stage="install"/>
  99. <jar src="jtds-1.2.4.jar" stage="install"/>
  100. <jar src="ibatis2-common-2.1.7.597.jar" stage="install"/>
  101. <!-- 引入本地类库,创建快捷方式时需要用到 -->
  102. <native type="izpack" name="ShellLink.dll"/>
  103. <native type="izpack" name="ShellLink_x64.dll"/>
  104. <!--
  105. The packs section.
  106. We specify here our packs.
  107. 需要打包的文件文件夹,以及打包的地址
  108. -->
  109. <packs>
  110. <pack name="tomcat" required="yes">
  111. <description>tomcat server</description>
  112. <file src="../tomcat7" targetdir="$INSTALL_PATH"/>
  113. <!-- The file will be parsed -->
  114. </pack>
  115. <pack name="station" required="yes">
  116. <description>station</description>
  117. <file src="../station" targetdir="$INSTALL_PATH"/>
  118. <!-- Reccursive adding -->
  119. </pack>
  120. </packs>
  121.  
  122. </installation>

上面是一个install.xml文件一个例子,其中添加了一些注释,下面详细讲一下各个标签的使用和作用:
  1. info标签:这个标签里包含了很多子标签,主要描述被安装的程序的基本信息,比如作者、使用的java版本等等,这些信息会展示在HelloPanel这个面板上
  2. guiprefs标签:这个标签里定义了安装程序窗口的大小、字体大小、各个面板上标签之间的X和Y方向间距、进度条的展示、按钮图片、窗口颜色等等
  3. locale标签:这个标签主要用于国际化,可以定义很多语言,供用户选择
  4. resources标签:这个标签主要用来引入自己的自定义资源,比如用户协议文档、用户输入面板、自定义处理面板等等
  5. panels标签:这个标签很重要,也是接下来讲述的重点,也是我们最关心的,这个标签里面定义了很多panel,每个panel就是我们熟悉的安装程序中的一步,点击上一步或者下一步可以跳到另一面板,因此这里定义的panel有顺序性,第一个panel标签就是安装程序第一个面板。IzPack提供了很多panel,有很多可以直接使用,像HelloPanel,有些需要自定义,比如UserInputPanel,我们的主要任务就是根据自己的需求,引入不同的panel,编写自己的panel。其实大家用的最多还是用户输入面板(UserInputPanel)和处理面板(ProcessPanel),后面会详细介绍这两个的使用
  6. packs标签:这里定义了安装程序需要把哪些文件安装到用户电脑中,每个pack标签都定义了一个安装任务,可以通过属性required来定义是否必须选择,或者由用户选择。上面例子中<file src="../station" targetdir="$INSTALL_PATH"/>这句话是关键,定义了需要把上级目录的station文件夹安装到用户指定的安装目录,其中$INSTALL_PATH就是指用户选择的安装目录。当编译这个安装包时,会把这些指定的文件文件夹打包放在安装包中,当用户点击安装时,直接从安装包解压复制到安装目录,复制的操作是在InstallPanel这个面板出现时进行,因此缺少这个panel,将不会把文件安装到指定目录,并且要注意InstallPanel在所有panels中的位置,因为有时我们需要动态修改安装后的文件,要使用$INSTALL_PATH来访问安装后的文件,如果还没有到InstallPanel,那么安装目录里什么文件都没有,我们将无法访问。

猜你在找的XML相关文章