如何覆盖 Java 的 jpackage wix 默认值以创建包含安装位置的环境变量?

问题描述

我有一个使用 jpackage (Java 14) 打包的桌面 Java 应用程序。

Windows 安装程序

我想知道如何修改/覆盖 jpackage wix 认值,以便在环境变量中捕获安装位置。

我已经尝试使用在 WiX 食谱:https://learning.oreilly.com/library/view/wix-cookbook/9781784393212/ch13s02.html

<Component Id="cmpEnvironmentvariable" 
           Guid="{313075B5-BF2C-4012-9A6E-2F4E2C461306}"  
           KeyPath="yes">
     
  <Environment Id="myEnvironmentvariable"   
               Name="MyVariable" 
               Value="some value" 
               Action="set" 
               System="yes" />
 
</Component>

我还尝试将环境变量添加到 jpackage 创建的 overrides.wxi 文件中,我不认为这是正确的做法。

这两次尝试都导致 jpackage 失败。

我也花时间浏览了 WIX 文档,但发现它相当难以理解。

任何提示、建议或示例将不胜感激。


参考:jpackage创建的认main.wxs:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

  <?ifdef JpIsSystemWide ?>
    <?define JpInstallScope="perMachine"?>
  <?else?>
    <?define JpInstallScope="perUser"?>
  <?endif?>

  <?define JpProductLanguage=1033 ?>
  <?define JpInstallerVersion=200 ?>
  <?define JpCompressedMsi=yes ?>

  <?include $(var.JpConfigDir)/overrides.wxi ?>

  <Product
    Id="$(var.JpProductCode)"
    Name="$(var.JpAppName)"
    Language="$(var.JpProductLanguage)"
    Version="$(var.JpAppVersion)"
    Manufacturer="$(var.JpAppvendor)"
    UpgradeCode="$(var.JpProductUpgradeCode)">

    <Package
      Description="$(var.JpAppDescription)"
      Manufacturer="$(var.JpAppvendor)"
      InstallerVersion="$(var.JpInstallerVersion)"
      Compressed="$(var.JpCompressedMsi)"
      InstallScope="$(var.JpInstallScope)" Platform="x64"
    />

    <Media Id="1" Cabinet="Data.cab" EmbedCab="yes" />

    <?ifdef JpAllowDowngrades ?>
    <?ifdef JpAllowUpgrades ?>
    <MajorUpgrade
      AllowDowngrades="yes"
      disallow="no"
    />
    <?endif?>
    <?endif?>

    <?ifdef JpAllowDowngrades ?>
    <?ifndef JpAllowUpgrades ?>
    <MajorUpgrade
      AllowDowngrades="yes"
      disallow="yes"
      disallowUpgradeErrorMessage="!(loc.disallowUpgradeErrorMessage)"
    />
    <?endif?>
    <?endif?>

    <?ifndef JpAllowDowngrades ?>
    <?ifdef JpAllowUpgrades ?>
    <MajorUpgrade
      AllowDowngrades="no"
      disallow="no"
      DowngradeErrorMessage="!(loc.DowngradeErrorMessage)"
    />
    <?endif?>
    <?endif?>

    <?ifndef JpAllowDowngrades ?>
    <?ifndef JpAllowUpgrades ?>
    <MajorUpgrade
      AllowDowngrades="no"
      disallow="yes"
      DowngradeErrorMessage="!(loc.DowngradeErrorMessage)"
      disallowUpgradeErrorMessage="!(loc.disallowUpgradeErrorMessage)"
    />
    <?endif?>
    <?endif?>

    <!-- Standard required root -->
    <Directory Id="TARGETDIR" Name="SourceDir"/>

    <Feature Id="DefaultFeature" Title="!(loc.MainFeatureTitle)" Level="1">
      <ComponentGroupRef Id="Shortcuts"/>
      <ComponentGroupRef Id="Files"/>
      <ComponentGroupRef Id="FileAssociations"/>
    </Feature>

    <?ifdef JpInstallDirChooser ?>
    <Binary Id="JpCaDll" SourceFile="wixhelper.dll"/>
    <CustomAction Id="JpCheckInstallDir" BinaryKey="JpCaDll" DllEntry="CheckInstallDir" />
    <?endif?>

    <UI>
      <?ifdef JpInstallDirChooser ?>
      <Dialog Id="JpInvalidInstallDir" Width="300" Height="85" Title="[ProductName] Setup" NoMinimize="yes">
        <Control Id="JpInvalidInstallDirYes" Type="PushButton" X="100" Y="55" Width="50" Height="15" Default="no" Cancel="no" Text="Yes">
          <Publish Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
        </Control>
        <Control Id="JpInvalidInstallDirNo" Type="PushButton" X="150" Y="55" Width="50" Height="15" Default="yes" Cancel="yes" Text="No">
          <Publish Event="NewDialog" Value="InstallDirDlg">1</Publish>
        </Control>
        <Control Id="Text" Type="Text" X="25" Y="15" Width="250" Height="30" TabSkip="no">
          <Text>!(loc.message.install.dir.exist)</Text>
        </Control>
      </Dialog>

      <!--
        Run WixUI_InstallDir dialog in the default install directory.
      -->
      <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR"/>
      <UIRef Id="WixUI_InstallDir" />

      <Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="JpCheckInstallDir" Order="3">1</Publish>
      <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="JpInvalidInstallDir" Order="5">INSTALLDIR_VALID="0"</Publish>
      <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="5">INSTALLDIR_VALID="1"</Publish>

      <?ifndef jplicenseRtf ?>
      <!--
        No license file provided.
        Override the dialog sequence in built-in dialog set "WixUI_InstallDir"
        to exclude license dialog.
      -->
      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2">1</Publish>
      <Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">1</Publish>
      <?endif?>

      <?else?>

      <?ifdef jplicenseRtf ?>
      <UIRef Id="WixUI_Minimal" />
      <?endif?>

      <?endif?>
    </UI>

    <?ifdef jplicenseRtf ?>
    <WixVariable Id="WixUILicenseRtf" Value="$(var.jplicenseRtf)"/>
    <?endif?>

  </Product>
</Wix>


参考:jpackage创建的认overrides.wxi:

<?xml version="1.0" encoding="utf-8"?>
<!-- Stub by design -->
<Include> 
           


</Include>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)