Ubuntu – No ‘Open with’ option to open/run jar file with openjdk


I have run

sudo apt-get install openjdk-7-jre

It says

Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-7-jre is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 229 not upgraded.

However, In my /usr/share/applications folder, there is no openjdk-7-jre.desktop.
The only file I have found on my computer related to openjdk is OpenJDK Java 7 Policy Tool. What have I done wrong?
I am using it to be able to run .jar files with a doubleclick. I can run them from terminal already, but there is no open with option for java

Best Answer

For some reason there is no desktop file for OpenJDK 7.

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

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

Install Java with this commands, in order to get the required entry:

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

and then

sudo apt-get install oracle-java7-set-default

Or you could create a desktop file for OpenJDK7

Create a new file in ~/.local/share/applications/

nano ~/.local/share/applications/openjdk7.desktop

and add the lines below:

[Desktop Entry]
Name=Open JDK 7 Runtime
Comment=Open JDK 7 Runtime
Exec=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -jar %f

Replace the line

Exec=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -jar %f

with the location of your java installation. You can check the installed JREs with:

update-alternatives --display java

Sample output

java - auto mode
  link currently points to /usr/lib/jvm/java-9-oracle/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071
  slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - priority 1081
  slave java.1.gz: /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-8-oracle/jre/bin/java - priority 1083
  slave java.1.gz: /usr/lib/jvm/java-8-oracle/man/man1/java.1.gz
/usr/lib/jvm/java-9-oracle/bin/java - priority 1084
Current 'best' version is '/usr/lib/jvm/java-9-oracle/bin/java'.