首页 > 解决方案 > 如何从 jpackage+wix 添加到 Windows 应用程序的快捷方式?

问题描述

我有一个脚本(为简洁起见只是一个简化的摘录)来构建和打包我的应用程序,但它归结为生成 WiX 安装程序:

jpackage \
    --type msi \
    --dest "$(cygpath -w "${base[build:dist]}")" \
    --name "${appDisplayName}" \
    --app-version "${version}" \
    --app-image "$(cygpath -w "${base[build:app]}")" \
    --license-file "$(cygpath -w resources/app/legal/LICENSE)" \
    --vendor "${vendor}" \
    --verbose \
    --temp 'W:\_tmp_' \
    --win-shortcut;

它因神秘而失败:Command [light.exe, (...)] in (...) exited with 94 code。我发现这是关于未解决的引用,特别是对快捷图标的引用:...\config\bundle.wxf(10) : error LGHT0094 : Unresolved reference to symbol 'Icon:icon1798580986' in section 'Fragment:'.

当我检查生成的 WiX XML 时,我发现:

<?xml version="1.0" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <Fragment>
  ...
  <DirectoryRef Id="DesktopFolder">
    <Component Win64="yes" Id="cshortcut9906e12cdacb303ebb5e48c888cf6949" Guid="{9906e12c-dacb-303e-bb5e-48c888cf6949}">
      ...
      <Shortcut Id="shortcut9906e12cdacb303ebb5e48c888cf6949" Name="..." WorkingDirectory="INSTALLDIR" Advertise="no" IconIndex="0" Target="[#filed2065cdc42e13
55f8bdbbefc93d540f3]" Icon="icon1798580986"></Shortcut>
    </Component>
  </DirectoryRef>
  ...
</Wix>

确实有这个“icon1798580986”值,它没有告诉我任何东西,甚至 WiX 也在这里丢失了(在阅读此https://stackoverflow.com/a/21019152/2024692后,我检查并确认我确实WixUIExtension.dll在 WiXbin文件夹)。

当我删除--win-shortcut选项时,会生成 MSI 安装程序,但不幸的是桌面上没有快捷方式图标(该应用程序具有正确的图标,因为我生成了带有--icon开关并--resource-dir指向 ao 应用程序图标的应用程序图像)。

正如您可能猜到的那样,这是从 Cygwin 调用的,所以有时它需要摆弄路径,尤其是当调用 Windows 可执行文件时(因此有这些cygpath东西)。

好吧,我找不到任何建设性的方法来简单地让我的 Java 应用程序jpackage(来自 JDK-14/15 EA 都没有成功)在安装后具有漂亮的快捷方式图标。有谁知道如何解决这个问题?提前致谢。

标签: javawindowswixcygwin

解决方案


使用 gradle 插件更容易

您需要设置正确的图标文件路径并拥有一个有效的 .ico 文件。我是这样做的:

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'PDF Decorator'
        jvmArgs = ['-Djdk.gtk.version=2'] // required due to a bug in Java: https://github.com/javafxports/openjdk-jfx/issues/175
    }
    jpackage {
        installerOptions = [
            '--description', project.description,
            '--copyright', 'Copyrigth 2015-2019 WALCZAK.IT'
        ]
        installerType = project.findProperty('installerType') // we will pass this from the command line (example: -PinstallerType=msi)
        if (installerType == 'msi') {
            imageOptions += ['--icon', 'src/main/resources/pdfdecorator/gui/icon.ico']
            installerOptions += [
                '--win-per-user-install', '--win-dir-chooser',
                '--win-menu', '--win-shortcut'
            ]
        }
        if (installerType == 'pkg') {
            imageOptions += ['--icon', 'src/main/resources/pdfdecorator/gui/icon.icns']
        }
        if (installerType in ['deb', 'rpm']) {
            imageOptions += ['--icon', 'src/main/resources/pdfdecorator/gui/icon_256x256.png']
            installerOptions += [
                '--linux-menu-group', 'Office',
                '--linux-shortcut'
            ]
        }
        if (installerType == 'deb') {
            installerOptions += [
                '--linux-deb-maintainer', 'office@walczak.it'
            ]
        }
        if (installerType == 'rpm') {
            installerOptions += [
                '--linux-rpm-license-type', 'GPLv3'
            ]
        }
    }
}

这是一篇文章如何使用 OpenJDK 11 构建应用程序映像并使用带有 jpackage 的 OpenJDK 14 仅用于构建安装程序/包:https ://walczak.it/blog/distributing-javafx-desktop-applications-without-requiring-jvm-使用-jlink-and-jpackage


推荐阅读