Problem running jar from gui in 15.04

7,305

Solution 1

For some reason the desktop file for OpenJDK is not installed, even though this file is listed.

$ apt-file list openjdk-8-jre | grep desktop        
openjdk-8-jre: /usr/share/applications/openjdk-8-java.desktop
openjdk-8-jre: /usr/share/applications/openjdk-8-policytool.desktop

$ ls -l /usr/share/applications/openjdk-8-java.desktop
ls: cannot access /usr/share/applications/openjdk-8-java.desktop: No such file or directory

$ dpkg --get-selections | grep openjdk-8
openjdk-8-jre:amd64             install

But you can also use Oracle Java(TM):

Install Oracle Java(TM) with this commands and you have an entry in open with:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

To select your default Java, use the following command.

sudo update-alternatives --config java

But this has no influence on the menu item "Open with"

Solution 2

Switching java to Oracle JDK is just a workaround in my opinion, as the OP wanted to know why it doesn't work anymore with OpenJDK. Anyway, I fixed it myself using this answer on Ask Fedora.

Basically you first have to create a file javajar.desktop with following contents in /usr/share/applications/.

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
NoDisplay=true
Exec=java -jar %f
Name=OpenJDK
Comment=Launching Jar files

After that, execute this command terminal to add your .desktop file to mimetypes list:

echo "application/x-java-archive=javajar.desktop" >> ~/.local/share/applications/mimeapps.list

Of course this all has to be done with root rights. Voilà, jars now immediately open as GUI.

Share:
7,305

Related videos on Youtube

Skadlig
Author by

Skadlig

Updated on September 18, 2022

Comments

  • Skadlig
    Skadlig over 1 year

    I updated ubunut to 15.04 today. Now when I try starting a jar file from the gui it only opens the archive manager.
    Checking the open with tab in Properties I can't find Openjdk. I got both Openjdk java 7 and 8 installed according to the software center but despite that they don't show up in the list.
    That means that the solution here: How run a .jar file with a double-click? doesn't work for me.

  • Skadlig
    Skadlig about 9 years
    If I want to use Openjdk, would I use apt-get install openjdk-8-jre-default instead?
  • A.B.
    A.B. about 9 years
    Sorry no, but if you don't have a major reason for the OpenJDK, then I would recommend Oracle.
  • A.B.
    A.B. about 9 years
    For this you need sudo update-alternatives --config java
  • Skadlig
    Skadlig about 9 years
    I don't need open sourced java as such so Oracle will do fine and your solution worked @A.B.
  • Skadlig
    Skadlig about 9 years
    Strange though that it stopped working after I did the upgrade from 14.10 to 15.04
  • A.B.
    A.B. about 9 years
    The desktop file is missing. No idea why.