简体   繁体   English

如何将 Java 应用程序绑定到 Gnome/Ubuntu 中的关联 .desktop 文件?

[英]How to bundle Java App to associated .desktop file in Gnome/Ubuntu?

Sorry, bu I didn't find any solution yet.抱歉,我还没有找到任何解决方案。 I have an executable jar file (JavaFx based app) which I can easy start from bash:我有一个可以从 bash 轻松启动的可执行 jar 文件(基于 JavaFx 的应用程序):

java -jar myapp.jar

I want this app to start from a side panel in Ubuntu, so I'm creating .desktop file and place it in /usr/share/applications directory.我希望这个应用程序从 Ubuntu 的侧面板启动,所以我正在创建 .desktop 文件并将它放在 /usr/share/applications 目录中。 And it works out, I see my app in apps list, mark it as Favorite and it appears in the side-panel ready for quick-access.成功了,我在应用程序列表中看到我的应用程序,将其标记为“收藏夹”,它会出现在侧面板中,可供快速访问。 But when I run it Gnome creates another associated .desktop file (temporary) and put a dot under that instead of using mine.但是当我运行它时,Gnome 会创建另一个关联的 .desktop 文件(临时)并在它下面放一个点而不是使用我的。

So, how to bundle my app with .desktop file ?那么,如何将我的应用程序与 .desktop 文件捆绑在一起? So, when I run my app I want Gnome to put a dot under the right .desktop file (from which I run it!!).所以,当我运行我的应用程序时,我希望 Gnome 在正确的 .desktop 文件下放一个点(我从中运行它!!)。 For example, when running Visual Code or Intellij Idea I have a dot under them, even if I do it from bash.例如,当运行 Visual Code 或 Intellij Idea 时,我在它们下面有一个点,即使我是从 bash 执行的。 Really, I search for idea.desktop file, see which executable it use, go to that executable and just run it from bash and it links with idea's icon!真的,我搜索idea.desktop 文件,查看它使用哪个可执行文件,转到该可执行文件,然后从bash 运行它,它会与idea 的图标链接!

/snap/bin/intellij-idea-ultimate

Of course, I'm not sure if it's usual executable, but anyway how does it work ?当然,我不确定它是否是通常的可执行文件,但无论如何它是如何工作的? I thought that the .desktop file is responsible for this linkage, but if I run executable from bash and gnome puts a dot under the right icon without need to be started from this icon...我认为 .desktop 文件负责此链接,但是如果我从 bash 运行可执行文件并且 gnome 会在正确的图标下放置一个点,而无需从此图标启动...

在此处输入图片说明

  1. Open a terminal打开终端
  2. run : xprop WM_CLASS运行:xprop WM_CLASS
  3. click on your application window单击您的应用程序窗口
  4. copy one of the string generated in the terminal复制终端中生成的字符串之一
  5. add it to your .desktop file.将其添加到您的 .desktop 文件中。 The key is "StartupWMClass".关键是“StartupWMClass”。 So it looks something like StartupWMClass="the string you copied earlier.所以它看起来像 StartupWMClass="你之前复制的字符串。

That should do it.那应该这样做。

For example this is how my firefox .desktop looks like例如,这是我的 firefox .desktop 的样子

 [Desktop Entry]
...
    StartupWMClass=Firefox
    StartupNotify=true
   [Desktop Entry]
   ....
   StartupWMClass=<fully qualified Application class name>

Example:例子:

   [Desktop Entry]
   ....
   StartupWMClass=org.mycompany.app.Application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM