How can I set the MacOS DMG volume icon using Java 17's jpackage utility?

230 views Asked by At

I'm creating a DMG installation package for my java application for use on OSX. I have the following script that creates a resources directory, puts some files in it, then runs the jpackage command to actually create the DMG. The problem is that the dmg file, when mounted, is using the app icon instead of the volume icon I have specified.

Here is the script:

# create resource directory for jpackage
printf "Creating resource directory..."
mkdir resources
cp "$APP_PATH"/src/main/resources/img/build-resources/moose-app-icon.icns "$APP_PATH"/deploy/resources/moose-app-icon.icns
cp "$APP_PATH"/src/main/resources/img/build-resources/moose180-spaced.png "$APP_PATH"/deploy/resources/moose-background.png
cp "$APP_PATH"/src/main/resources/img/build-resources/moose180-spaced.png "$APP_PATH"/deploy/resources/moose-background-darkAqua.png
cp "$APP_PATH"/src/main/resources/img/build-resources/moose-volume.icns "$APP_PATH"/deploy/resources/moose-volume.icns
echo "Done."

#   actually building the package
printf "Building installation package..."
$jdk/jpackage \
  --resource-dir "$APP_PATH"/deploy/resources \
  --type dmg \
  --input . \
  --main-jar moose.jar \
  --name Moose \
  --app-version "$version" \
  --icon resources/moose-app-icon.icns \
  --description "Moose" \
  --verbose
echo "Done."

After the first step, which moves resources around, the "$APP_PATH"/deploy/resources/ directory looks like this:

/deploy
  /resources
    - moose-app-icon.icns
    - moose-background-darkAqua.png
    - moose-background.png
    - moose-volume.icns

This is the process laid out in the jpackage documentation for JDK 17 under the Override jpackage Resources section. It mentions to have a app-name-volume.icns file in your resource directory, which I do have (moose-volume.icns), but it's instead using the app icon (moose-app-icon.icns).

When I use the --verbose flag in the jpackage command, I get the following output from the creation script:

[21:47:08.776] Using custom package resource [icon] (loaded from file /Users/mpfthprblmtq/Git/moose/deploy/resources/moose-app-icon.icns).
[21:47:08.776] Preparing Info.plist: /var/folders/0t/hr0vs3715v15xzjpfqpmkns40000gn/T/jdk.jpackage15144647471455641486/images/image-4445575315167377480/Moose.app/Contents/Info.plist.
[21:47:08.777] Using default package resource Info-lite.plist.template [Application Info.plist] (add Info.plist to the resource-dir to customize).
[21:47:08.778] Using default package resource Runtime-Info.plist.template [Java Runtime Info.plist] (add Runtime-Info.plist to the resource-dir to customize).
[21:47:08.779] Using default package resource background_dmg.tiff [dmg background] (add Moose-background.tiff to the resource-dir to customize).
[21:47:08.779] Using custom package resource [volume icon] (loaded from file /Users/mpfthprblmtq/Git/moose/deploy/resources/moose-app-icon.icns).
[21:47:08.780] Preparing dmg setup: /var/folders/0t/hr0vs3715v15xzjpfqpmkns40000gn/T/jdk.jpackage15144647471455641486/config/Moose-dmg-setup.scpt.
[21:47:08.780] Using default package resource DMGsetup.scpt [DMG setup script] (add Moose-dmg-setup.scpt to the resource-dir to customize).
[21:47:08.781] Creating DMG file: /Users/mpfthprblmtq/Git/moose/deploy/Moose-1.4.0.dmg.

This tells me that jpackage is using my moose-app-icon.icns when I explicitly have the moose-volume.icns file at the same level as the main app icon. Any ideas on how I can tell jpackage to use the moose-volume.icns file instead of the app icon?

I am on OSX Ventura 13.2.1, and my jpackage version is 17.0.3.

1

There are 1 answers

1
Cromax On

According to information on the web page you provided yourself:

macOS DMG

  • DMG setup script, application-name-dmg-setup.scpt.
  • Applications license properties list, application-name-license.plist.
  • Background file, application-name-background.tiff.
  • Drive icon, application-name-volume.icns.

So you should use moose.icns for the application icon, moose-volume.icns for the volume icon AND --name moose as your application name (note small caps). If you choose to name your application Moose, then update icons to Moose.icns and Moose-volume.icns – it's case sensitive and it actually works for my app, but application-name part must match exactly your application name (specified by --name option).