How can I make a .jar file executable?

You can always run a jar file by doing java -jar JMerise.jar.

However, to make the jar file itself executable, you need to set the executable bit, as the message hints. chmod +x /home/aimad/Programms/jMerise/JMerise.jar will accomplish this.

After that you can do ./JMerise.jar to run it.

man chmod will provide you with information about how chmod works.

Also see: https://wiki.ubuntu.com/Security/ExecutableBit


Right click on the file, click on properties, then go to the Permissions tab, and check the box that says "Allow executing this file as a program".

enter image description here


First you'll need to make sure you have a suitable Java runtime environment on your system. Ubuntu has openjdk in the official repo which is 99.99% combatible with Oracle Java, to install it type:

sudo apt-get install openjdk-7-jre

Next create a file called java-jar-launcher.desktop in ~/.local/share/applications and put the following contents in it:

[Desktop Entry]
Type=Application
Name=Java Application Launcher
Icon=java
Exec=/usr/bin/java -jar %U
Categories=Application;Java
Terminal=False

Next add the following line in ~/.local/share/applications/mimeapps.list:

application/x-java-archive=java-jar-launcher.desktop;

Now you should be able to just double click jar files to launch them, if nothing happens then right click on a jar file, select properties then go to the "Open With" tab and there you should see "Java Application Launcher", select that.

This method is prefferable (IMHO) because this way you are not giving execute permissions to jar files which can be potentially dangerous. This method will only work in a graphical environment and needs the user to manually double click on the file.

Tags:

Openjdk