Running a Java program from Nautilus

As @puneetse said, Nautilus lists applications according to the MimeType they have in there *.desktop files.
In I did a `grep -iR ‘.jar’ /usr/share/mime’ and below is the output

./application/x-java-archive.xml:  <glob pattern="*.jar"/>
./globs:application/x-java-archive:*.jar
./globs2:50:application/x-java-archive:*.jar
./packages/freedesktop.org.xml:    <glob pattern="*.jar"/>

In /usr/share/mime/application/x-java-archive, it says

  <alias type="application/x-jar"/>
  <alias type="application/java-archive"/>
  <glob pattern="*.jar"/>

Then it turns out on my system the only application that opens jar is org.gnome.FileRoller.desktop, which is the archive manager of gnome.

So I made a desktop file myself with the following

[Desktop Entry]
Type=Application
Version=1.0
Name=Jar Opener
# This is for opening files, not launching the notebook from a menu
NoDisplay=true
Exec=java -jar %f
Terminal=true
MimeType=application/x-java-archive;

It’s also available here.

Place it under ~/.local/share/applications and run `update-desktop-database ~/.local/share/applications’ and you’re good to go.

P.S. I have to specify the directory when update-desktop-database, otherwise it doesn’t work, because it’s not in $XDG_DATA_DIRS. Maybe we should patch filesystem package to include this directory.

1 Like