In console running a jar file is normally done by java -jar application.jar Is there a way to run jar files by executing ./application.jar? I'd like this behaviour for any jar file. I tried chmod +x application.jar but it won't work as it gives the following error: invalid file (bad magic number): Exec format error. Further, it would be specific to one application.

marked as duplicate by muru command-line Dec 17 '17 at 1:08

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.


.jar file is not executable by itself.. its just a modified(compiled and ziped) text file; the executable is the /usr/bin/java which sits on a path known to the system; that is why you can type java -jar app.jar and it works

./command means this folder in another shell loaded in this one(the command shell);

. command means this folder this shell


you can define an alias for the repetitive part java -jar


type alias inside a terminal to see already defined aliases

type your presumed alias to see if it returns command not found so you can use it

then type alias command='java -jar' to define the alias

after that you can use it as command app.jar


edit the .bashrc file from your home folder and add an alias like the one in temporary save and exit and relog


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