We all know that there are some commands i.e. executables we can run directly from terminal without having to set the full path for them. For e.g. all the executables in the /usr/bin
I have a jar file that I am currently running by the command java -jar jarName.jar {arguments}
Is there a way that I can run my jar as well similarly without writing the whole command java -jar path_to_jar/jarName.jar {arguments}
I would like to write something like
appName {arguments}
and want the jar to get the arguments and execute just like it would have if I had written java -jar path_to_jar/jarName.jar
I am open to making the jar file an executable and putting it in /usr/bin so that it can accessed from anywhere. But I do not know how to do this. The following did not help at all Tutorial to make jar executable
Best Answer
You might want to try to make a bash script that executes your command. In your case it would look like this :
The "$*" takes all arguments given to the bash script and send them directly to your java program. The last thing to do is to save your script in /usr/bin/myprogram.sh Then you will be able to execute it directly as a command in the terminal: