This question already has an answer here:

I have an .sh file that looks like

exec /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/
java java -jar /home/me/myfolder/my.jar

I've made this file executable and it works fine when in the "nautilus" desktop, but when I run it on just normal desktop (Ubuntu 14.04) it only opens with gedit. I have also tried opening it with Java 7 and Java 6, but it does not give me the option to run in terminal. Also when i'm in the terminal and cd to the folder containing the .jar file and run it that also works fine. What I'm looking for is a way to just double click my .sh file without having to go to nautilus first. Is this possible?

Sorry if this is a duplicate, but I cant find the answer I'm looking for.

marked as duplicate by terdon, Jacob Vlijm, Radu Rădeanu command-line Sep 12 '14 at 17:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I am not sure I understand the difference between a nautilus desktop and a "normal" desktop. It is both nautilus. – Jacob Vlijm Sep 12 '14 at 15:53
  • Maybe I'm using the wrong term then because in order for me to execute that file I have to go into the terminal sudo nautilus and then another file manager comes up. When I double click it in the new file manager it executes correctly and does not open to the gpedit – ShaadShaad Sep 12 '14 at 15:57
  • Eek. Nautilus has this preference settings for handling executable files. It looks like your "root" nautilus has this set to "always run", and your own has this set to "always view". – muru Sep 12 '14 at 16:06

You can create a desktop file and make it executable, then run it from nautilus or desktop directly. Here is an example:

Create a file using:

gedit myjar.desktop

Copy and paste the code below:

#!/usr/bin/env xdg-open
[Desktop Entry]
Exec=java -jar my.jar
Name=My Java Gui

Some entries like path are optional.

Make it executable:

chmod +x myjar.desktop

Run it from nautilus.

  • Maybe I'll have to retrace some steps the terminal is telling me its either invalid or corrupted. Thanks for you help – ShaadShaad Sep 12 '14 at 17:36

When you have made it executable with chmod +x file/name.sh, you can run it by typing ./file/name.sh in terminal.

Edit: Actually just read what you where trying to do. Try commenting out the "exec" line of the script, and change the second line to ./home/me/myfolder/my.jar after you have run chmod +x /home/me/myfolder/my.jar.

I don't know much about java, but I have run some java programs like this.

  • Yes that is correct, but can I just double click my .sh and it run automatically? I'm trying to make this easy for people not familiar with linux or the terminal at all. – ShaadShaad Sep 12 '14 at 16:09
  • Edited my answer a bit. Hope it helps. – Dan Johansen Sep 12 '14 at 16:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.