Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a jar file in Linux [closed]

Tags:

java

linux

jar

I have created an executable Java .jar file. That is to say, I properly packaged a java program inside a .jar file, including a META-INF/MANIFEST file.

(Incidentally, on most Windows machines with Java installed, .jar files are registered to run as something like javaw.exe -jar %1, so you can just double click jars that have been prepared in that way.)

I just copied the same file into Linux and tried to do the same thing.

But, when I click on that file it is just opening the jar as a zip file, rather than invoking java.

How can I configure my Linux system so that the program inside the jar executes when I double click on the jar file? That is, how can I make my system invoke something like java -jar test.jar when I double click test.jar?

like image 760
Pankaj Singhal Avatar asked Jan 25 '26 07:01

Pankaj Singhal


2 Answers

Make your file executable:

sudo chmod +x test.jar
like image 100
0xAX Avatar answered Jan 26 '26 20:01

0xAX


Heh, what @marc is trying to say in his comment is that how you do that could be wildly different depending on your linux flavor. In general, you just need to find out how to change the default "Open With" behavior for whichever flavor you're using. You need to tell it to open jar files with Java instead of with the archive program.

like image 35
Ryan Stewart Avatar answered Jan 26 '26 19:01

Ryan Stewart