IzPack 替换文本文件中的变量

发布于 2024-10-09 10:59:50 字数 102 浏览 4 评论 0原文

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

有什么想法吗?

提前致谢。

I'm trying to figure out how to have IzPack replace variables in text files. It seems like it should be a simple thing but I can't find a specific example of doing this with their existing documentation.

Any ideas?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

a√萤火虫的光℡ 2024-10-16 10:59:50

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

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

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

I assume that the file to be processed is added to one of the packs using file or fileset tag. In order for that file to be processed, which happens just at the end of the installation process, it is necessary to add the parsable tag for the file to the same pack. For example

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

There are three parsable tags in the above example -- two OS dependent, and one OS independent. The target files are first copied to corresponding target directories specified in the respective file tags and then processed by substituting variable names in the files with their values.

铁憨憨 2024-10-16 10:59:50

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>

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>

Building on 01es' answer this is an example where you let the user choose a path for the application's data using the UserInputPanel and then write that path to a config file inside the installation directory for your application to read.

The example config.xml that contains variables you want to substitute:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文