diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java index 2c78a408f4..010369758d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java @@ -69,17 +69,22 @@ public class RunMojo extends AbstractRunMojo { @Override protected void runWithForkedJvm(File workingDirectory, List args, Map environmentVariables) throws MojoExecutionException { + int exitCode = forkJvm(workingDirectory, args, environmentVariables); + if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) { + return; + } + throw new MojoExecutionException( + "Application finished with exit code: " + exitCode); + } + + private int forkJvm(File workingDirectory, List args, + Map environmentVariables) throws MojoExecutionException { try { RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString()); Runtime.getRuntime() .addShutdownHook(new Thread(new RunProcessKiller(runProcess))); - int exitCode = runProcess.run(true, args, environmentVariables); - if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) { - return; - } - throw new MojoExecutionException( - "Application finished with exit code: " + exitCode); + return runProcess.run(true, args, environmentVariables); } catch (Exception ex) { throw new MojoExecutionException("Could not exec java", ex);