【问题标题】:IzPack replacing variables in text filesIzPack 替换文本文件中的变量
【发布时间】:2010-12-27 12:13:45
【问题描述】:

我试图弄清楚如何让 IzPack 替换文本文件中的变量。看起来这应该是一件简单的事情,但我找不到使用他们现有文档的具体示例。

有什么想法吗?

提前致谢。

【问题讨论】:

标签: java installation izpack


【解决方案1】:

我假设要处理的文件是使用文件或文件集标签添加到其中一个包中的。为了处理该文件,这发生在安装过程结束时,有必要将文件的可解析标记添加到同一个包中。例如

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

在上面的例子中有三个可解析的标签——两个依赖于操作系统,一个独立于操作系统。目标文件首先被复制到相应文件标签中指定的相应目标目录中,然后通过将文件中的变量名替换为其值来处理。

【讨论】:

    【解决方案2】:

    以01es' answer 为基础,这是一个示例,您可以让用户使用UserInputPanel 选择应用程序数据的路径,然后将该路径写入安装目录中的配置文件以供您的应用程序读取。

    示例config.xml 包含要替换的变量:

    <?xml version="1.0" encoding="UTF-8"?>
    <Entries>
      <Entry>
        <Key>appDataDir</Key>
        <!-- IzPack will substitute this -->
        <Value>$appDataDir</Value>
      </Entry>
    </Entries>
    

    userInputSpec.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>
    

    installer.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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-20
      • 2017-12-03
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      相关资源
      最近更新 更多