2

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?

Community
  • 1
  • 1
Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86
  • what linux? ubuntu, fedora, debian, mandriva, mint? what desktop? kde, gnome, ...? what file manager? nautilus? konqueror? what version of all of them? – marc Jul 17 '11 at 15:50
  • If you still did not found your solution on how to configure your desktop, look on unix.stackexchange.com (for Linux in general), superuser.com (even more general) or askubuntu.com (if you want to configure your Ubuntu system). You can flag this question for migration using the *flag* link. – Paŭlo Ebermann Jul 17 '11 at 23:26
  • For future seekers: You might be looking for `binfmt_misc`. http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/java.txt?id=HEAD – daveloyall Feb 02 '16 at 20:23
  • You might also be looking for the Debian package called `jarwrapper`! – daveloyall Feb 02 '16 at 20:26

4 Answers4

5

Make your file executable:

sudo chmod +x test.jar
0xAX
  • 20,957
  • 26
  • 117
  • 206
4

One possible way would be to make a text file with that command java -jar test.jar in it, then give that file execute permissions. Name it test Then you would double click that file (or via the command line just type ./test)

Dylan
  • 13,645
  • 3
  • 40
  • 67
4

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.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
3

Personally, I'd leave the jar file as is and create a script that will execute the command when it is clicked, then I'd just click on that.

What window manager / desktop are you using in linux? You can likely configure the default action of a click on a jar file.

mikey
  • 5,090
  • 3
  • 24
  • 27