4

IzPack でテキスト ファイル内の変数を置き換える方法を見つけようとしています。簡単なことのように思えますが、既存のドキュメントでこれを行う具体的な例は見つかりません。

何か案は?

前もって感謝します。

4

2 に答える 2

5

処理対象のファイルは、file または fileset タグを使用していずれかのパックに追加されると想定しています。そのファイルを処理するには (インストール プロセスの最後に発生します)、ファイルの解析可能なタグを同じパックに追加する必要があります。例えば

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

上記の例には、解析可能なタグが 3 つあります。2 つは OS に依存し、1 つは OS に依存しません。ターゲット ファイルは、最初にそれぞれのファイル タグで指定された対応するターゲット ディレクトリにコピーされ、次にファイル内の変数名をそれらの値に置き換えることによって処理されます。

于 2011-01-20T10:24:25.753 に答える
2

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>

インストーラー.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>
于 2014-12-17T12:33:24.437 に答える