IzPack replaces variables in text files

I am trying to figure out how to replace IzPack variables in text files. It sounds like it should be simple, but I cannot find a concrete example of this with their existing documentation.

Any ideas?

Thanks in advance.

+3
source share
2 answers

Based on 01es answer , you can select the path for the application data using UserInputPanel , and then write this path to the configuration file inside the installation directory to read your application.

An example config.xmlcontaining the variables you want to replace:

<?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>
+2

, , , , . , , parsable .

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

- . , , .

+5

Source: https://habr.com/ru/post/1782274/


All Articles