使用 Launch4j 将 Java 应用程序固定到 Windows 7 任务栏
我目前正在尝试将 Java 应用程序固定到 Windows 7 任务栏.该应用程序通过 Launch4j 启动.程序图标显示正确,但右键单击任务栏上的图标仅显示带有条目关闭窗口"的上下文菜单.没有用于将应用程序固定到任务栏的菜单项.将 EXE 文件拖入任务栏也无法正常工作.在任务栏中单击这个新启动器时,任务栏中会出现第二个图标.
I'm currently trying to pin a Java application to the Windows 7 taskbar. The application is launched with Launch4j. The program icon is displayed correctly but right-clicking the icon on the taskbar only shows a context-menu with the entry "Close window". No menu entry for pinning the application to the taskbar. Dragging the EXE file into the taskbar is also not working properly. When clicking this new launcher in the taskbar then a second icon spawns in the taskbar.
我按照这两个问题的解决方案的说明解决了问题,但没有帮助:
I followed the instructions of the solutions to these two questions to solve the problem but it didn't help:
- 将 Java 应用程序固定到 Windows 7 任务栏一个>
- 使用 JNA 获取/设置应用标识符
第二个问题/解决方案中的 JNA 内容会编译并且不会引发任何异常.设置后我可以读取应用程序ID.但我仍然无法将应用程序固定到任务栏.
The JNA stuff from the second question/solution compiles and doesn't throw any exception. I can read the app id after setting it. But I still can't pin the application to the taskbar.
我在 Github 上创建了一个小型测试应用程序来演示该问题:
I have created a small test application on Github which demonstrates the problem:
https://github.com/kayahr/launch4jtest
应用程序使用 Maven 作为构建系统.只需运行mvn package
,您会在目标目录中找到一个ZIP 文件,其中包含EXE 文件和设置此应用程序ID 所需的jna.jar.将此 ZIP 解压缩到某个目录,双击 EXE 并尝试将应用程序固定到任务栏,您会看到问题.
The application uses Maven as build system. Simply run mvn package
and you'll find a ZIP file in the target directory which contains the EXE file and the jna.jar which is needed to set this app id. Extract this ZIP to some directory, double-click the EXE and try to pin the application to the taskbar and you'll see the problem.
那么这个应用程序有什么问题呢?
So what's wrong with this application?
推荐答案
N.B.应kayahr的要求重写了最初在主帖中的一些评论:)
N.B. Rewritten some comments originally in the main post as per kayahr's request :)
您需要创建一个嵌入AppUserModelID信息的图标快捷方式.InnoSetup 可以在 [Icons]
部分下创建这样的图标快捷方式.提供通过 JNA 分配给 AppUserModelID 的应用程序名称.推荐阅读链接:
You need to create an icon shortcut that embeds AppUserModelID information. InnoSetup can create such icon shortcut under [Icons]
section. Supply the application name assigned to AppUserModelID via JNA. Suggested links to read:
如何为 izpack 安装程序制作 .exe 文件.jar 文件
Launch4j、NSIS 和复制固定的 Windows 7 任务栏图标
- 它在将 EXE 文件(不是其图标快捷方式)拖放到 Windows 7 任务栏以创建固定图标时起作用;
- 它在运行 EXE 文件并稍后选择固定到任务栏"选项菜单以创建固定图标时起作用.如果不设置AppUserModelID,这是不可能的;即使它会导致奇怪的行为,例如在任务栏上使用 javaw.exe 图标"而不是您的 exe 图标,因为 Launch4J 使用 javaw.exe 调用可执行 jar(重复的固定图标)
- It works when dragging and dropping the EXE file (not its icon shortcut) into Windows 7 taskbar to create a pinned icon;
- It works when running the EXE file and later choosing "pin to taskbar" option menu to create a pinned icon. If you don't set AppUserModelID, this is not possible; even it will cause a weird behavior like having javaw.exe "icon" on the taskbar instead of your exe icon since Launch4J calls the executable jar using javaw.exe (duplicated pinned icons)
要在 Linux 下运行基于 Windows 的安装程序生成器,请参考以下内容:
To run Windows-based installer builder under Linux, refer this as a guide:
http://katastrophos.net/andre/blog/2009/03/16/setting-up-the-inno-setup-compiler-on-debian/
是的,正如 kayahr 所说,此 Windows 7 功能仅在其嵌入 AppUserModelID 的图标快捷方式保持不变(即未移除/删除)时才有效.
Yes, as mentioned by kayahr, this Windows 7 feature will only work when its icon shortcut with embedded AppUserModelID remains intact (i.e. it is not removed/deleted).
相关文章