问题
I found this SpringBoot Application code which throws Exit Code 10 when executed with argument "exitcode".
public class Swagger2SpringBoot implements CommandLineRunner {
@Override
public void run(String... arg0) throws Exception {
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
throw new ExitException();
}
}
public static void main(String[] args) throws Exception {
new SpringApplication(SpringBootEntityApp.class).run(args);
}
class ExitException extends RuntimeException implements ExitCodeGenerator {
private static final long serialVersionUID = 1L;
@Override
public int getExitCode() {
return 10;
}
}
}
Running this code with the given argument exits the program.
java -jar exitcode arg1 arg2
I would be grateful if somebody could explain the use-case of this code.
PS: Why are we running the program to exit the program.
References:
Swagger Petstore.
Plaza Client
Yidi
Stack Overflow Question 1
Docker Dash
来源:https://stackoverflow.com/questions/58618988/why-if-arg0-length-0-arg00-equalsexitcode