Passing parameters to Java executable in Unix shell script?
Does anyone know how to pass input parameters to a Java executable program, which is called by a Unix shell script?
I am replacing COBOL stand-alone batch programs with Java stand-alone programs. The Java programs will be called from shell scripts to create reports, which require input parameters. Multiple shell scripts can exist to create the same report only differing in the input parameters.I have ruled out using an XML file to provide the input since it can only hold the last reports input parameters.
Please help :)
Yes, you put a line in the script that looks like this:java classname parameter1 parameter2 parameter3 ...
Then the JVM will call the static main(String[] args) method of "classname" and put those parameters into the "args" array.
If you are asking how to generate such a script, or how to call it from your COBOL program, sorry, I don't know how to do that.
If you are asking how to pass the parameters to the script to java, you can use:
java -cp classpath main-class $1 $2 ...
or
java -cp classpath main-class $*
or if you are running into issues with the passing quoted parameters you can use this jewel (don't ask me how it works, I just know it does)
java -cp classpath main-class ${1+"$@"}