使用 Launch4j 将 Java 应用程序固定到 Windows 7 任务栏

发布于 2025-01-06 12:02:29 字数 1082 浏览 4 评论 0 原文

我目前正在尝试将 Java 应用程序固定到 Windows 7 任务栏。该应用程序通过 Launch4j 启动。程序图标显示正确,但右键单击任务栏上的图标仅显示带有“关闭窗口”条目的上下文菜单。没有用于将应用程序固定到任务栏的菜单条目。将 EXE 文件拖到任务栏也无法正常工作。当在任务栏中单击这个新的启动器时,任务栏中会出现第二个图标。

我按照这两个问题的解决方案的说明来解决问题,但没有帮助:

第二个问题中的 JNA 内容/解决方案编译并且不会引发任何异常。设置后我可以读取应用程序ID。但我仍然无法将应用程序固定到任务栏。

我在 Github 上创建了一个小型测试应用程序来演示该问题:

https://github.com/kayahr/launch4jtest< /a>

该应用程序使用 Maven 作为构建系统。只需运行mvn package,您就会在目标目录中找到一个 ZIP 文件,其中包含 EXE 文件和设置此应用程序 ID 所需的 jna.jar。将此 ZIP 解压缩到某个目录,双击 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:

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.

I have created a small test application on Github which demonstrates the problem:

https://github.com/kayahr/launch4jtest

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何其悲哀 2025-01-13 12:02:29

注意:根据 kayahr 的要求重写了主帖中的一些评论:)

您需要创建一个嵌入 AppUserModelID 信息的图标快捷方式。 InnoSetup可以在[Icons]部分创建这样的图标快捷方式。提供通过 JNA 分配给 AppUserModelID 的应用程序名称。建议阅读的链接:

如何制作 .exe 文件izpack 安装程序 .jar 文件

Launch4j、NSIS 和重复的固定 Windows 7 任务栏图标

  1. href 将 EXE 文件(不是其图标快捷方式)拖放到 Windows 7 任务栏以创建固定图标时有效;
  2. 它在运行 EXE 文件并随后选择“固定到任务栏”选项菜单来创建固定图标时起作用。如果不设置AppUserModelID,这是不可能的;即使它会导致奇怪的行为,例如任务栏上有 javaw.exe“图标”而不是 exe 图标,因为 Launch4J 使用 javaw.exe 调用可执行 jar(重复的固定图标)

要在 Linux 下运行基于 Windows 的安装程序生成器,请参阅此作为指南:

http://katastrophos.net/andre/blog/2009/03/16/setting-up-the-inno-setup-compiler-on-debian/

是的,正如提到的kayahr,这个 Windows 7 功能只有在嵌入 AppUserModelID 的图标快捷方式保持不变(即没有被删除/删除)时才起作用。

N.B. Rewritten some comments originally in the main post as per kayahr's request :)

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:

How to make .exe file for izpack installer .jar file

Launch4j, NSIS, and duplicate pinned Windows 7 taskbar icons

  1. It works when dragging and dropping the EXE file (not its icon shortcut) into Windows 7 taskbar to create a pinned icon;
  2. 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)

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/

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).

绾颜 2025-01-13 12:02:29

我使用 InnoSetup 为我的 java 应用程序创建安装程序。要使我的应用程序的图标可固定,我执行两个步骤:

  1. 为我的应用程序设置 AppUserModelID:
  • 从 Maven 添加包:net.java.dev.jna/jna-platform-5.7.0

  • set AppUserModelID

    WString id = new WString("TMP.TestApp");
    Shell32.INSTANCE.SetCurrentProcessExplicitAppUserModelID(id);

  1. 使用 InnoSetup 创建图标时使用 AppUserModelID

    [图标]

    名称:“{commondesktop}\TestApp”;文件名:“{app}\run.bat”;工作目录:“{app}”;图标文件名:“{app}\test-icon.ico”; AppUserModelID: "TMP.TestApp";标志:运行最小化

I use InnoSetup to create installer for my java application. To make my app's icon pinable I do two steps:

  1. Set AppUserModelID for my app:
  • Add package from Maven: net.java.dev.jna/jna-platform-5.7.0

  • set AppUserModelID

    WString id = new WString("TMP.TestApp");
    Shell32.INSTANCE.SetCurrentProcessExplicitAppUserModelID(id);

  1. Use AppUserModelID when creating icon with InnoSetup

    [Icons]

    Name: "{commondesktop}\TestApp"; Filename: "{app}\run.bat"; WorkingDir: "{app}";IconFilename:"{app}\test-icon.ico"; AppUserModelID: "TMP.TestApp"; Flags: runminimized

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文