1

I want to open a .jar file with java. It is located in /home/myusername. I had to type in the terminal to open it

java -jar filename.jar

I want to have a shortcut that if I click it, it will run the command and launch the program with java automatically..

is there anything I could do?

sourav c.
  • 44,715

2 Answers2

3

You can create a .desktop file on your desktop using your favourite text editor and save the following code in a it.

[Desktop Entry]
Encoding=UTF-8
Name=myjavafile
Type=Application
Exec=java -jar /home/myusername/filename.jar
Icon=/path/to/java.jpg

You need to change Name and jar file name in Exec field. If you want to set an icon for it put a 128x128 .jpg or .png image for java and specify it accordingly on Icon field. Otherwise remove the last line.

enter image description here

Give it execution permission,

chmod +x /home/myusername/Desktop/<filename>.desktop

Now you can click on it to open your jar file using java directly.

sourav c.
  • 44,715
1

First create an Empty Document and name it yourchoosenname.sh

(.sh means that this file contain commands to run )

enter image description here

Second open this file and add the code you write in Terminal, adjusting the path as appropriate:

java -jar /home/$USER/filename.jar

Third make this file executable:

Right click on the file, then to the Permissions tab.

enter image description here

Fourth run this file by double clicking.

kiri
  • 28,246
  • 16
  • 81
  • 118
nux
  • 38,017
  • 35
  • 118
  • 131
  • 1
    Please don't post commands as images, it means we have to copy your suggestion by hand in order to try it. That's what code blocks are for. – terdon Mar 13 '14 at 02:34
  • why your are trying to down vote all my answers !! what should you copy here ? and you dont have the right to tell me what to do – nux Mar 13 '14 at 04:50
  • images are allowed and people should learn how to write commands , not only copy paste – nux Mar 13 '14 at 04:51
  • 4
    I did not tell you what to do, I asked you to please not post images of commands. I also (in my other comment pointed you to the meta question where this was discussed. But you're quite right, the images you posted here are fine. I was looking for posts that had commands as images to edit them but I read too quickly and thought this one needed it as well. My apologies. – terdon Mar 13 '14 at 05:16