shell - Return value from a Java code -
there java class creates post request , sends servlet. main method of class file (test) looks this:
public static void main(string[] args) throws ioexception { // code logic goes here... // no return statement } this called kornshell (ksh) script this:
retcode=`$clk_java_path -cp $classpath test ${password} ${hostname} ${toolset}` if [ $? != "0" ];then echo "error: echo "${retcode}" else echo "${script} success" fi retcode has value "2" independent of if code fails or succeeds. question since return type of main method "void" why code returning value?
the return value of java application not return value of it's main method, because java application doesn't end when it's main method has finished execution.
instead jvm ends when no more non-daemon threads running or when system.exit() called.
and system.exit() way specify return value: argument passed system.exit() used return value of jvm process on os.
so ending main() method this:
system.exit(0); will ensure 2 things:
- that java application exits when end of
mainreached and - that return value of jvm process 0
Comments
Post a Comment