我试图弄清楚如何让 IzPack 替换文本文件中的变量。看起来这应该是一件简单的事情,但我找不到使用他们现有文档执行此操作的具体示例。
有任何想法吗?
提前致谢。
我试图弄清楚如何让 IzPack 替换文本文件中的变量。看起来这应该是一件简单的事情,但我找不到使用他们现有文档执行此操作的具体示例。
有任何想法吗?
提前致谢。
我假设要处理的文件使用文件或文件集标记添加到其中一个包中。为了处理该文件,这发生在安装过程的最后,有必要将文件的可解析标签添加到同一个包中。例如
<packs>
<pack name="Base" required="yes">
<description>Application and all its dependencies.</description>
<fileset dir="dependencies" targetdir="$INSTALL_PATH/dependencies" />
<file src="Licence.txt" targetdir="$INSTALL_PATH" />
<file src="application.properties" targetdir="$INSTALL_PATH/dependencies" />
<file src="run.bat" targetdir="$INSTALL_PATH" os="windows" />
<file src="run.sh" targetdir="$INSTALL_PATH" os="unix" />
<parsable targetfile="$INSTALL_PATH/run.bat" os="windows" />
<parsable targetfile="$INSTALL_PATH/run.sh" os="unix" />
<parsable targetfile="$INSTALL_PATH/dependencies/application.properties" />
</pack>
</packs>
上面的例子中有三个可解析的标签——两个依赖于操作系统,一个独立于操作系统。目标文件首先被复制到相应文件标签中指定的相应目标目录中,然后通过将文件中的变量名称替换为它们的值来进行处理。
基于01es 的回答,这是一个示例,您让用户使用UserInputPanel选择应用程序数据的路径,然后将该路径写入安装目录中的配置文件,供您的应用程序读取。
config.xml
包含要替换的变量的示例:
<?xml version="1.0" encoding="UTF-8"?>
<Entries>
<Entry>
<Key>appDataDir</Key>
<!-- IzPack will substitute this -->
<Value>$appDataDir</Value>
</Entry>
</Entries>
用户输入规范.xml:
<userInput>
<panel id="panel1">
<field type="dir" variable="appDataDir">
<spec size="20" set="$USER_HOME\AppData\Roaming\$APP_NAME" mustExist="false" create ="true"/>
<os family="windows"/>
</field>
</panel>
</userInput>
安装程序.xml:
<?xml version="1.0" encoding="UTF-8"?><installation version="1.0">
<info>
<appname>Your app</appname>
<appversion>0.0.1</appversion>
<!-- Try to run as the administrator on Windows to be able to install under "C:\Program Files" -->
<run-privileged condition="izpack.windowsinstall" />
</info>
<locale>
<langpack iso3="eng" />
</locale>
<resources>
<res id="userInputSpec.xml" src="userInputSpec.xml" parse="yes" type="xml" />
</resources>
<panels>
<panel classname="UserInputPanel" id="panel1" />
<panel classname="InstallPanel" />
<panel classname="FinishPanel" />
</panels>
<packs>
<pack name="Core" id="core.package" required="yes">
<description>The base files that need to be part of the app</description>
<!-- The runnable application should be in this directory -->
<fileset dir="YourAppDir" targetdir="$INSTALL_PATH/YourAppDir">
<include name="**" />
</fileset>
<!-- This file contains placeholder variables starting with $ that Izpack substitutes with values that the user enters during installation in the UserInputPanel -->
<parsable targetfile="$INSTALL_PATH/YourAppDir/config.xml" />
</pack>
</packs>
</installation>