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.
  • 46,120

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.
  • 46,120
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,986
nux
  • 39,152