Java – izpack replaces variables in text files

I tried to figure out how to replace variables with izpack in text files It seems that it should be a simple thing, but I can't find a specific example of using existing documents to do this@ H_ 301_ 7@

Solution

Build on 01es' answer. This is an example. You can let the user use userinputpanel to select the path of application data, and then write the path to the configuration file in the installation directory for the application to read@ H_ 301_ 7@

<?xml version="1.0" encoding="UTF-8"?>
<Entries>
  <Entry>
    <Key>appDataDir</Key>
    <!-- IzPack will substitute this -->
    <Value>$appDataDir</Value>
  </Entry>
</Entries>
<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 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>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>