1

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.

theJack
  • 131

1 Answers1

0
echo '#!/usr/bin/java -jar' > my-command

cat myJar.jar >> my-command

chmod +x my-command

./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.