1

I got a script (just a simplified excerpt for brevity) to build and package my app, but it boils down to generating WiX installer with:

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;

It fails with enigmatic: Command [light.exe, (...)] in (...) exited with 94 code. Which I found is about unresolved reference and particularly a reference to a shortcut icon: ...\config\bundle.wxf(10) : error LGHT0094 : Unresolved reference to symbol 'Icon:icon1798580986' in section 'Fragment:'.

When I examined generated WiX XML, I found this:

<?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>

And indeed there's this "icon1798580986" value, which does not tell me anything and even WiX is lost here (after reading this this https://stackoverflow.com/a/21019152/2024692 I checked and confirmed that I actually do have WixUIExtension.dll in WiX bin folder).

When I remove --win-shortcut option, then MSI installer is generated, but unfortunately w/o shortcut icon on the desktop (the app has it's proper icons, thou, as I generated application image with --icon switch and with --resource-dir pointing to a.o. app icons).

As you probably guessed, this is called from Cygwin, so sometimes it needs fiddling with paths, especially when one calls Windows executables (hence these cygpath things).

Well, I wasn't able to find any constructive approaches how to simply allow my Java application packed with jpackage (from both JDK-14/15 EA with no success) to have nice shortcut icon after it gets installed. Does anyone knows how to fix this? Thanks in advance.

Cromax
  • 1,822
  • 1
  • 23
  • 35
  • Have you found a solution for incorporating the icon? I just gave up creating a desktop shortcut. – David Cian Apr 25 '20 at 18:15
  • 1
    @DavidCian Unfortunately not yet. I was hoping to run postinstall script (the shortcut can be created via batch script), but it seems, like postinstall works on macOS and Linux, but not on Windows (at least I was not able to run it on Windows). If you, on the other hand, managed to run postinstall script on Windows, then I would happily share the code (but I suppose, you would figure it out instantly by your own means). – Cromax Apr 26 '20 at 16:04

3 Answers3

3

its easier to do with a gradle plugin

You need to set the proper icon file path and have a valid .ico file. This is how I did it:

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'
            ]
        }
    }
}

Here's an article how to build an app image using OpenJDK 11 and using OpenJDK 14 with jpackage only for building the installer / package: https://walczak.it/blog/distributing-javafx-desktop-applications-without-requiring-jvm-using-jlink-and-jpackage

Adam from WALCZAK.IT
  • 1,339
  • 12
  • 11
  • 1
    This simply adds the same option I was referring to. – Cromax Mar 04 '20 at 23:30
  • I've edited the anwser, see if this code spit helps you – Adam from WALCZAK.IT Mar 05 '20 at 12:00
  • You mean that it might be worth to notice, that it adds, besides `--win-shortcut` (as in my excerpt), also `--icon` parameter? Hm, I should give it a try, however I put `--icon` in previous step (not listed here) while building an app image. But maybe this could be the thing? I'll check and give the feedback. – Cromax Mar 05 '20 at 19:39
  • Unfortunately `--icon` does not work with `--type msi` for `jpackage` (it does for `--type app-image`, thou, yet it is not reflected in generated MSI installer that uses an app-image created in such a way). – Cromax Mar 13 '20 at 12:46
1

If error 94 happens without --win-shortcut

This might actually be a problem relating to the --app-image parameter given to jpackage! An indicator for that is the warning that the app-image wasn't created by jpackage.

If your destination parameter when creating the app-image looks like --dest target/app-image, then you have to use --app-image target/app-image/myapp when creating the installer. Using --app-image target/app-image results in this error. A minor oversight that can create a lot of head-scratching because of the cryptic message.

This seems to happen for the reason @Mumrah81 gave:

[...] jpackage expect to find the executable and the icon at the root of app-image directory to create the shortcut.

mindoverflow
  • 364
  • 1
  • 12
0

You just had the pleasure given by convention over configuration

When using jpackage --app-image and --win-shorcut parameters then jpackage expect to find the executable and the icon at the root of app-image directory to create the shortcut. The executable and the icon must have the same name as the one provided using the --name parameter.

In your case jpackage expects:

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

to exists to be able to create the shortcut.

Mumrah81
  • 2,034
  • 2
  • 16
  • 23
  • Did not tested that yet — `jpackage` from JDK 14.0.1 works on previous config as expected, thou. – Cromax Jun 10 '20 at 12:02