jpackage linux creates insufficient desktop file
Asked Answered
A

1

3

I just started using jpackage and it is a really great tool. One single step takes a lot of work off my shoulders. The more surprised I am about something that looks hardcoded and cannot be customized?

JPackage automatically generates the launcher (lib/<application>.desktop file), and the deb package automatically installs it such that all users can launch the application. But as soon as it is launched, another icon pops up in unity. I expected that the existing icon is marked as running.

According to Ubuntu DEB installer makes all Java applications have the same icon we just need to ensure the .desktop file contains the correct StartupWMClass. Using xprop I found out this value is based on the fully qualified class name responsible for the window - which makes absolute sense.

So how can I tell jpackage which StartupWMClass to set in the generated .desktop file?

Edit: To complement Bodo's comment I will show how I call jpackage. In fact I am not running a command line myself - instead I am using the maven plugin configured as:

        <plugin>
            <groupId>com.github.akman</groupId>
            <artifactId>jpackage-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jpackage</goal>
                    </goals>
                    <configuration>
                        
          <dest>target</dest>
          <name>OoliteCommunicator</name>
          <type>PLATFORM</type>
          <appversion>${project.version}</appversion>
          <description>Oolite Communicator is an add-on for Oolite to allow multiplayer interaction. (check http://oolite.org)</description>
          <vendor>Hiran</vendor>
          <icon>target/classes/com/mycompany/oolitecommunicator/ui/Communicator_Logo_Icon.png</icon>
          <input>target/dist</input>
          <mainjar>OoliteCommunicator-${project.version}.jar</mainjar>
          <mainclass>com.mycompany.oolitecommunicator.Main</mainclass>
                        
                    </configuration>
                </execution>
            </executions>
        </plugin>

What I can see during the maven build is this output, which I believe to be the command line generated internally when the plugin invokes jpackage. The last line may be the invocation already, and whenever I check after the build there is no file /home/hiran/NetBeansProjects/OoliteCommunicator/target/jpackage.opts. I can only assume it's content was logged just before.

# jpackage
--dest /home/hiran/NetBeansProjects/OoliteCommunicator/target
--app-version '1.0-20211220-090022'
--description 'Oolite Communicator is an add-on for Oolite to allow multiplayer interaction. (check http://oolite.org)'
--name 'OoliteCommunicator'
--vendor 'Hiran'
--icon /home/hiran/NetBeansProjects/OoliteCommunicator/target/classes/com/mycompany/oolitecommunicator/ui/Communicator_Logo_Icon.png
--input /home/hiran/NetBeansProjects/OoliteCommunicator/target/dist
--main-jar 'OoliteCommunicator-1.0-20211220-090022.jar'
--main-class com.mycompany.oolitecommunicator.Main
/usr/lib/jvm/java-16-openjdk-amd64/bin/jpackage @/home/hiran/NetBeansProjects/OoliteCommunicator/target/jpackage.opts

Finaly I get a deb package with this desktop file:

[Desktop Entry]
Name=OoliteCommunicator
Comment=Oolite Communicator is an add-on for Oolite to allow multiplayer interaction. (check http://oolite.org)
Exec=/opt/oolitecommunicator/bin/OoliteCommunicator
Icon=/opt/oolitecommunicator/lib/OoliteCommunicator.png
Terminal=false
Type=Application
Categories=Unknown
MimeType=

and I fixed the bhaviour by manually adding the line

StartupWMClass=com-mycompany-oolitecommunicator-Main

So my workaround is to add this line to both

  • /opt/oolitecommunicator/lib/oolitecommunicator-OoliteCommunicator.desktop
  • /usr/share/applications/oolitecommunicator-OoliteCommunicator.desktop

after the deb has been installed. Not that easy as jpackage was intended for I guess...

Arundel answered 20/12, 2021 at 10:45 Comment(6)
Please show in your question the complete jpackage command you are using, and if you use @filename, the contents of the file.Rockling
I added more information. Sorry that I cannot provide the command line directly.Arundel
The contents of /home/hiran/NetBeansProjects/OoliteCommunicator/target/jpackage.opts may also be important. I suggest to try --main-class class name, see docs.oracle.com/en/java/javase/14/docs/specs/man/…Rockling
I added the information as you suggested. My POM is updated, the log when calling jpackage is updated, but the resulting .desktop file is the same. :-(Arundel
You should add the information to the question what exactly you added which did not help to get the StartupWMClass line in the launcher file. If you don't see a file /home/hiran/NetBeansProjects/OoliteCommunicator/target/jpackage.opts then this file probably gets generated automatically before running the command and deleted afterwards. Sorry, my suggestion was based on the documentation only. I can only suggest to run jpackage manually and experiment with the options to find out if you can somehow get it to create the .desktop file as required. Then proceed to the maven integration.Rockling
The point is: by looking at the docs I do not see any hint for StartupWMClass. By looking at the source (github.com/openjdk/jdk/tree/master/src/jdk.jpackage/linux/…) neither code nor template mention StartupWMClass. It seems to not exist in the whole tool.Arundel
A
1

So finally I found a possibility to have the right packaging.

You need to override the JPackage internal template and provide your own .desktop file. This can be done by overriding JPackage resources.

It means you create a resource folder with the correct .desktop file inside, specify the resource folder on the JPackage command line and the correct package will be created.

Arundel answered 20/1, 2022 at 23:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.