Package and install a xxx.desktop file with javapackager

101 views Asked by At

I've packaged an application with Maven's JavaPackager plugin targetting Linux.

Everything is working fine except that I don't find how to package and install a "xxxx.desktop" file for my application.

Without this file, 1/ the icon on the launcher is ugly, 2/ the application cannot be found with a Search.

Here is my plugin's config:

<plugin>
    <groupId>io.github.fvarrui</groupId>
    <artifactId>javapackager</artifactId>
    <version>1.6.7</version>
    <configuration>
        <mainClass>com.zparkingb.zploger.GUI.Zploger</mainClass>
        <generateInstaller>false</generateInstaller>
        <administratorRequired>false</administratorRequired>
    </configuration>
    <executions>
        <execution>
            <!-- With JRE -->
            <id>bundling-for-platform-complete</id>
            <phase>package</phase>
            <goals>
                <goal>package</goal>
            </goals>
            <configuration>
                <platform>linux</platform>
                <name>${project.bundle_finalname}${package.buildnamesuffix}</name>
                <outputDirectory>${project.build.directory}/FULL</outputDirectory>
                <createTarball>true</createTarball>
                <createZipball>false</createZipball>
                <bundleJre>true</bundleJre>
                <customizedJre>false</customizedJre>
                <!--From settings.xml-->
                <jrePath>${package.jrePath}</jrePath>
                <jdkPath>${package.jdkPath}</jdkPath>
                <!--Special for Linux-->
                <linuxConfig>
                    <pngFile>assets/linux/Zploger.png</pngFile>
                    <generateAppImage>true</generateAppImage>
                    <generateDeb>false</generateDeb>
                    <generateRpm>false</generateRpm>
                    <wrapJar>true</wrapJar>
                    <categories>
                        <category>Utility</category>
                    </categories>
                </linuxConfig>
            </configuration>
        </execution>
    </executions>
</plugin>

So I'd need to end up with file:

~/.local/share/applications/com-zparkingb-zploger-GUI-Zploger.desktop

with a similar content:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name=Zploger for Scores
Icon=/home/vboxuser/Desktop/ZplogerScores/Zploger.png

Or even having the icon placed somewhere in ~/.local/share/icons/xxx/xxx and having the ".desktop" file refering to it as Icon=Zploger

How could I achieve this ?

1

There are 1 answers

0
lvr123 On

My solution is probably far from being ideal, but I am limited in that I am building a Linux solution from a Windows environment.

The solution is based on the following principle:

  1. Have the application startup script checking for the presence of the icons and the .desktop file in ~/.local/share/applications/.

  2. If it doesn't exist, copy these from the package.

So the solution must

  1. Adapt the default startup script in order to do that extra check
  2. Add in the packaging the desktop file and the icons.

In the end, the solution is comprised of the following 4 steps:

  1. Add to the project folder the icons and the desktop file. I've put these in a bundledata/linux/assets folder. The folder name is free but cannot be assets\ because this one is reserved for JavaPackager and cannot one of the Maven resources folder because I want these files to packaged separately.

  2. Provide an adapted startup.sh.vtl velocity template which goal is to add to the startup script instructions to copy the icons and a valid desktop file.

The icons are copied to ~/.local/share/icons/hicolor/. And I provide "./16x16", "./24x24", ... "./1024x1024". And also "./scalable" with a SVG version of the application icon.

The desktop file is named my-main-class.desktop (in my case com-zparkingb-zploger-GUI-Zploger.desktop) and is copied into ~/.local/share/applications/

  1. Have that script modifying the xxx.desktop to push the current script path.

  2. Adapt the pom.xml. In the io.github.fvarrui.javapackager plugin's config, add the following instruction:

<additionalResources>
    <additionalResource>bundledata/linux/assets</additionalResource>
</additionalResources>