Tuesday, July 27, 2010

Bash: simple wrapper script for java jar files

There could be thousands of other (probably better) ways of writing a wrapper bash script for executing jar files on command line (instead of having to do "java -jar tool.jar"). For whatever it is worth, here's what I came up in quick 2 minutes. One can optimize according to his/her needs inside the for loop:
    1 #!/bin/bash
2
3 path='/home/USERNAME/android-sdk-linux_86/tools'
4
5 args=''
6 for ((i=$#;i>0;i--))
7 do
8 args="${args} ${1}"
9 shift
10 done
11
12 java -jar $path/tool.jar "$args"
13
14