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.

- 271
1 Answers
.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
http://www.linfo.org/dot_slash.html
you can define an alias for the repetitive part java -jar
temporary
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
permanent
edit the .bashrc
file from your home folder and add an alias like the one in temporary save and exit and relog

- 441
':ExecutableJAR:E::jar::/usr/local/bin/jarwrapper:'
instead of:CLR:M::MZ::/usr/bin/mono:
, wherejarwrapper
essentially runsjava -jar "$@"
. See https://wiki.archlinux.org/index.php/Binfmt_misc_for_Java for more – muru Dec 17 '17 at 01:10jarwrapper
but when I enter./myjarfile.jar
zsh shows this error:zsh: permission denied: ./myjarfile.jar
. After that I created/etc/binfmt.d/ExecutableJAR.conf
with the following content:ExecutableJAR:E::jar::/usr/bin/jarwrapper:
. I changed the path tojarwrapper
becausewhich jarwrapper
shows/usr/bin/jarwrapper
. Then I reboot my system. After that I'm still gettingzsh: permission denied: ./myjarfile.jar
. What's wrong? – menteith Dec 17 '17 at 12:59