In the good old days of C you had int main(...)
as the entry function and you could call the executable from a batch file and check %errorlevel%
in that batch file which would contain the return value.
In java I compile my java application to something.jar
and mark a function like public static void main(String[] rawArgs)
as the entry point. I then call java -jar something.jar
from the batch file. I can even append command line arguments if I want to.
But now I can't check %errorlevel%
since my main function is returning a void.
I suppose this is all perfectly logical given that everything is running in a virtual machine and that is the actual executable rather than something.jar
.
I can use System.exit(...) to achieve my original aim.
My question is this: Is there a better way of doing this? Killing off the virtual machine seem heavy handed. What if the code runs server side? Am I missing a cute function like Runtime.SetErrorLevel which does what I want?