如何从jpackage + wix向Windows应用添加快捷方式?

时间:2020-02-25 18:33:40

标签: java windows wix cygwin

我有一个脚本(为简洁起见,是一个简化的摘录)来构建和打包我的应用程序,但是归结为使用以下命令生成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之后,我检查并确认我确实在WiX中拥有WixUIExtension.dll bin文件夹)。

当我删除--win-shortcut选项时,将生成MSI安装程序,但是不幸的是,没有桌面上的快捷方式图标(您使用的图标是正确的图标,因为我使用--icon生成了应用程序映像切换,并--resource-dir指向ao应用程序图标。

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

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

2 个答案:

答案 0 :(得分:1)

使用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以及将OpenJDK 14和jpackage一起使用来构建应用程序映像,仅用于构建安装程序/软件包:https://walczak.it/blog/distributing-javafx-desktop-applications-without-requiring-jvm-using-jlink-and-jpackage

答案 1 :(得分:0)

您刚刚获得了约定带来的配置乐趣

使用jpackage --app-image--win-shorcut参数时,jpackage期望在app-image目录的根目录中找到可执行文件和图标以创建快捷方式。可执行文件和图标的名称必须与使用--name参数提供的名称相同。

在您的情况下,jpackage期望:

$(cygpath -w "${base[build:app]}")\${appDisplayName}.exe
$(cygpath -w "${base[build:app]}")\${appDisplayName}.ico

to可以创建快捷方式。