Last Updated: February 25, 2016
·
1.135K
· konstantin

Running jar with default arguments

After reading this tip I had an idea. Suppose you have a .jar file and you wanna make an executable with default args, so that you can just click on it and it will make everything right.

Normally you would create some make file or some shell script that would make a call with those args specified. But you can also do something like this:

1 . Create some file that would ask java to execute itself:

#!/bin/bash
java -Darg1=value1 -Darg2=value2 -jar $0
exit 0

Don't forget to leave a blank line at the end.

2 . Put the jar into the sh file:

cat some.jar >> some.sh

3 . Make that file executable:

chmod +x ./some.sh

That's it! =)