Search code examples
javalinuxjpackage

jpackage linux creates insufficient desktop file


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


Solution

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