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?

2 Answers 2

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.

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.

4
  • 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, 2014 at 2: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, 2014 at 4:50
  • images are allowed and people should learn how to write commands , not only copy paste
    – nux
    Mar 13, 2014 at 4: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, 2014 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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