29

I have a problem running .jar files by double-clicking them. When I go to the Properties dialogue I can't find Java--only Archive Manager in the list of programs. But java -jar somefile.jar opens the program.

5 Answers 5

26

Maybe you don’t have the runtime environment installed!

To install it try the following instructions.

sudo apt-get install openjdk-7-jre

Or you could install Oracle JRE using the PPA method with the following commands.

sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

Then to use it to open .jar files try the following.

  1. Right click the .jar file > Properties.
  2. Click on the “Open With” tab along the top.
  3. Change the default choice to be the java runtime environment that you have installed.
  4. Click Close and you should be ready to double click.
0
21

Adding a file called /usr/share/applications/java.desktop with following content should do the trick.

[Desktop Entry]
Name=Java
Comment=Java
GenericName=Java
Keywords=java
Exec=java -jar %f
Terminal=false
X-MultipleArgs=false
Type=Application
MimeType=application/x-java-archive
StartupNotify=true

After adding this file you should be able to find an entry called Java in the Open file with...-Dialog

2
  • I assume this .desktop file only gets created if you install the openjdk JRE and not when you install the openjdk JDK, even though the JDK includes the JRE?
    – earlio
    Jul 3, 2015 at 6:29
  • Is there any way you can get it to ask you to run in the terminal, perhaps by setting the Terminal value to Terminal=prompt? Jul 14, 2015 at 23:50
17

To make Java open .jar files per default (i.e. double click) right click on any .jar file to select Properties. In the following window select the "Open With" tab to see e.g. the follwing choice:

enter image description here

Select your Java runtime and press Set as default to make this your default application to open .jar files.

1
  • What in case if after installation JRE with apt-get install default-jre (which is 11 at Debian/Gnome3 for today) this recommended app still does not appear at all? Tried to reboot, with no luck.
    – biesior
    Sep 29, 2020 at 22:29
3

APPLICATION LAUNCHER

After installing the Java runtime environment you can create a launch icon like other applications in the system by making a *.desktop file.
It makes things easier and prettier!

  • Create a folder in a directory of your choice with the *.jar (the application) and *.png (the application icon) files. In this case the directory I will use is /usr/share/folder. For the ~/folder is a good idea to name it with the application name, for example, if the application is VUE name the folder ~/VUE or ~/vue.

    Open the terminal and run the following code line:

    sudo mkdir /usr/share/folder
    

    Or open your file manager (Nautilus in this case) with super admin privileges by runing the following code line in the terminal:

    gksu nautilus
    

    After that, go to /usr/share and create the folder folder with the GUI.

  • Also in the terminal and run the following code line:

    gksu gedit /usr/share/applications/*.desktop
    

    (You could use your editor of choice. In this case was used Gedit.)

  • Paste the following code lines in the file you are editing:

    [Desktop Entry]  
    Encoding=UTF-8  
    Name=Name  
    Categories=Category Name  
    Exec=java -jar /usr/share/folder/*.jar  
    Icon=/usr/share/folder/*.png  
    StartupNotify=false  
    Terminal=false  
    Type=Application  
    Comment=Application Name  
    StartupWMClass=Class  
    MimeType=application/*
    
  • Save the file. (The * is always the same name.)


APPLICATION ICON

For the icon sizes, Linux support a variety of image formats (PNG, JPG, SVG, etc.) and sizes (16x16 ~ 512x512 px). You could use a 32x32 ~ 96x96 px PNG file, or a 128x128 ~ 512x512 px SVG file for better results. In this case I think that a 96x96 px PNG is enough for a nice Desktop/Dash.

For more, take a look at:


FILE ASSOCIATION

For this step you have to create a MIME Tipe, if it doesn't exist, and associate it with the application in the mimeapps.list file. For that take a look on the following:


Note: If you find something incorrect, please feel free to edit and correct. Thanks!

0

I am using Xfce 4 with Thunar file manager. I've installed Oracle JDK by downloading archive file from Oracle's official web site. I've extracted contents to my local folder and added Java to PATH. So I am able to execute following command from terminal

java -version

You can start *.jar files from terminal with following command

java -jar filename.jar

But if you want to start it by double-clicking on file I've done following steps, don't forget that I am using Thunar file manager on Xfce 4, steps may differ;

  1. Right click on *.jar file
  2. Select "Open with another program"
  3. Check "Use specific command" checkbox
  4. Enter following command and click OK

    java -jar
    

When you double click on the *.jar file it will execute a command (second command that I gave above) in the background and start Java program.

Edit:When runtime installed via archive extraction, runtime won't show up on the list of application selector. I want to point that users can use commands if they added Java to PATH.

3
  • I'm not sure what this adds to the existing answers. The process you are describing doesn't appear to be substantially different from the accepted answer.
    – Elder Geek
    Dec 16, 2017 at 16:13
  • @ElderGeek When runtime installed via archive extraction, runtime won't show up on the list of application selector. I just wanted to point that users can use commands if they added Java to PATH. Dec 16, 2017 at 16:36
  • A nice graphical tool to add open-as program shortcuts is menulibre, where you can select an icon, edit existing commands etc
    – phil294
    Mar 25, 2020 at 18:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .