是否可以?
YES.
Jpackage 提供了进一步自定义使用构建的安装程序包的能力WiX https://wixtoolset.org/.
你必须使用--resource-dir
为此,正如中所解释的打包工具用户指南 https://docs.oracle.com/en/java/javase/14/jpackage/override-jpackage-resources.html#GUID-1B718F8B-B68D-4D46-B1DB-003D7729AAB6.
获取默认main.wxs
使用以下命令:
jpackage --input my_app [...] --temp "some/dir"
您将生成以下文件结构:
\some\dir
\config
my_app.ico
my_app.properties
main.wxs
MsiInstallerStrings_en.wxl
MsiInstallerStrings_ja.wxl
MsiInstallerStrings_zh.wxl
overrides.wxi
\images
\wixobj
复制main.wxs
文件到选择的目录中,例如my_resource_dir
.
您不需要任何其他东西,因此您可以安全地删除它以及生成的安装包。
更改 main.wxs 以将安装目录附加到路径变量
更改行my_resource_dir/main.wxs
:
<Feature Id="DefaultFeature" Title="!(loc.MainFeatureTitle)" Level="1">
<ComponentGroupRef Id="Shortcuts"/>
<ComponentGroupRef Id="Files"/>
<ComponentGroupRef Id="FileAssociations"/>
</Feature>
to:
<Feature Id="DefaultFeature" Title="!(loc.MainFeatureTitle)" Level="1">
<ComponentGroupRef Id="Shortcuts"/>
<ComponentGroupRef Id="Files"/>
<ComponentGroupRef Id="FileAssociations"/>
<Component Id="pathEnvironmentVariable" Guid="{YOUR_GUID}" KeyPath="yes" Directory="TARGETDIR">
<Environment Id="MyPathVariable" Name="Path" Value="[INSTALLDIR]" Action="set" System="no" Permanent="no" Part="last" Separator=";" />
</Component>
</Feature>
确保更换YOUR_GUID
与生成的 GUID生成器工具 https://www.guidgen.com/。例如:[...] Guid="{607ea423-79e0-4866-9ed7-62005b88d225}"
创建附加到路径的安装程序:
运行以下命令:
jpackage --input my_app [...] --resource-dir "my_resource_dir" --verbose
在日志输出中,您应该看到类似以下内容的内容:
[...] Using custom main.wxs file [...]
Result
现在构建的安装程序会将您的 INSTALLDIR 添加到安装路径中,并在卸载过程中将其删除。