0

How do I setup Unity to right-click-open a java file? I have tried to "set the default action" but the action is not listed and I cannot add an action from the menus. When I right-click-properties then click the "open with" tab, the "add" button is greyed out.

I write alot of java software. I need the ability to open it from the Desktop.

3 Answers3

1

Open /usr/share/applications and look for a file named "OpenJDK Java 6 Runtime". If it doesn't exists create a file named /usr/share/applications/openjdk-6-java.desktop with the following contents:

[Desktop Entry]
Name=OpenJDK Java 6 Runtime
Comment=OpenJDK Java 6 Runtime
Exec=cautious-launcher %f /usr/lib/jvm/java-6-openjdk-i386/bin/java -jar
Terminal=false
Type=Application
Icon=openjdk-6
MimeType=application/x-java-archive;application/java-archive;application/x-jar;
NoDisplay=true

You should change the "/usr/lib/jvm/java-6-openjdk-i386/bin/java" part of Exec to the location of java on your system. Then reboot and the option should be there.

NCode
  • 146
0

An easy way

Install OpenJDK with:

sudo apt install default-jre

Enter in the terminal:

sudo nano /usr/share/applications/java.desktop

Copy the following content:

[Desktop Entry]
Encoding=UTF-8
Name=Java
Comment=Java Virtual Machine
Exec=java -jar
Icon=java
Terminal=false
Type=Application
NoDisplay=true
Categories=Applications;
MimeType=application/x-java-archive;application/x-jar;

Note: Don't worry about putting the full path of java in the exec= line as it is not necessary since the system detects it automatically.

and paste it into nano using "Ctrl + V", then press Ctrl + O (Control and O at the same time) to save the changes, nano will ask for confirmation of the file name, press Enter to confirm writing to the file: /usr/share/applications/java.desktop and press ENTER. Then press Ctrl + X (Control and X at the same time) to exit the nano editor.

Papirus icon theme Additionally, I need to use the icon theme:

Papirus

https://github.com/PapirusDevelopmentTeam/papirus-icon-theme

Install and use it

This theme has Java icons in:

/usr/share/icons/Papirus/16x16/apps/java.svg
/usr/share/icons/Papirus/16x16/apps/java.svg
/usr/share/icons/Papirus/22x22/apps/java.svg
/usr/share/icons/Papirus/24x24/apps/java.svg
/usr/share/icons/Papirus/32x32/apps/java.svg
/usr/share/icons/Papirus/48x48/apps/java.svg
/usr/share/icons/Papirus/64x64/apps/java.svg

That's why in the java.desktop file, the Icon= line has java. This will enable right-click functionality in file managers.

0

14.04 LTS user here. Got OpenJDK working from desktop with:

contents of /usr/share/applications/openjdk-7-java.desktop

[Desktop Entry]
Name=OpenJDK Java 7 Runtime
Comment=OpenJDK Java 7 Runtime
Exec=cautious-launcher %f /usr/lib/jvm/java-7-openjdk-amd64/bin/java -jar 
Terminal=false
Type=Application
Icon=openjdk-7
MimeType=application/x-java-archive;application/java-archive;application/x-jar;
NoDisplay=true
Jim Ladd
  • 136