This question already has an answer here:

I often run Java .jar files, but in order to do so, I must invoke it with the command java -jar myJar.jar. Simply making the .jar executable will not allow it to be run, since it is not fully compiled. The .jar must also be in my current directory to do so.

What I am asking is is there any way to make it so that I can run a .jar by simply invoking it with myJar, provided it is in somewhere defined by $PATH? Is there any way to specify that it must be run with the Java interpreter?

I am using the Oracle JDK.

marked as duplicate by Eric Carvalho, amc, TheWanderer, Kevin Bowen, Severus Tux Oct 15 '16 at 6:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    You could make an alias or function that does java -jar part. I have done something similar with file manager some time ago to double click on jar file and run them in open terminal. But i haven't seen simply calling a jar file by name. Good question. – Sergiy Kolodyazhnyy Jul 25 '16 at 1:09
  • 7
    Possibly related to askubuntu.com/questions/101746/… (particularly the second answer) – Nick Weinberg Jul 25 '16 at 1:11
  • @NickWeinberg That is basically exactly what I was looking for. Please post it as an answer so that I can accept it. – theJack Jul 26 '16 at 0:08
echo '#!/usr/bin/java -jar' > my-command

cat myJar.jar >> my-command

chmod +x my-command


This answers your question (for a particular jar). If you make your own jars, it's easy to do the above using exec-maven plugin. If it's not your own jars, you could write a bash script to automate the above for multiple files.

  • 1
    Doesn't solve OP's problem because it has to be done for every jar file. – UTF-8 Oct 13 '16 at 21:51
  • Ya, it would take minutes to automate it to multiple files – Neil McGuigan Oct 14 '16 at 0:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.