英文:
How can I set the MacOS DMG volume icon using Java 17's jpackage utility?
问题
以下是您提供的脚本的翻译部分:
# 为jpackage创建资源目录
printf "创建资源目录..."
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 "完成。"
# 实际构建安装包
printf "构建安装包..."
$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 "完成。"
此外,您还提到了问题,即DMG文件在挂载时使用应用程序图标而不是您指定的卷标图标。您的日志显示jpackage正在使用moose-app-icon.icns
,而您实际上希望它使用moose-volume.icns
。您想知道如何告诉jpackage使用moose-volume.icns
而不是应用图标。
英文:
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
得分: 2
根据您提供的网页信息:
macOS DMG
- DMG设置脚本,application-name-dmg-setup.scpt。
- 应用程序许可属性列表,application-name-license.plist。
- 背景文件,application-name-background.tiff。
- 驱动器图标,application-name-volume.icns。
因此,您应该将moose.icns
用作应用程序图标,将moose-volume.icns
用作卷标图标,并使用 --name moose
作为应用程序名称(请注意小写)。如果您选择将应用程序命名为 Moose,那么请将图标更新为 Moose.icns
和 Moose-volume.icns
- 它对我的应用程序实际上起作用,但 application-name 部分必须与您的应用程序名称完全匹配(由 --name
选项指定)。
英文:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论