sproketboy sproketboy - 9 months ago 65
Java Question

izpack replacing variables in text files

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?


Answer Source

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"?>
    <!-- IzPack will substitute this -->


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


<?xml version="1.0" encoding="UTF-8"?><installation version="1.0">
    <appname>Your app</appname>
    <!-- Try to run as the administrator on Windows to be able to install under "C:\Program Files" -->
    <run-privileged condition="izpack.windowsinstall" />

    <langpack iso3="eng" />

    <res id="userInputSpec.xml" src="userInputSpec.xml" parse="yes" type="xml" />

    <panel classname="UserInputPanel" id="panel1" />
    <panel classname="InstallPanel" />
    <panel classname="FinishPanel" />

    <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="**" />

      <!-- 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" />