@Test public void runJar() throws Exception { File target = new File("target"); File[] jarFiles = target.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.getName().endsWith(".jar"); } }); assertThat(jarFiles).hasSize(1); Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); process.waitFor(5, TimeUnit.MINUTES); assertThat(process.exitValue()).isEqualTo(0); String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); assertThat(output).contains("Spring Boot Ant Example"); }
@Override protected void runWithForkedJvm(List<String> args) throws MojoExecutionException { try { RunProcess runProcess = new RunProcess(new JavaExecutable().toString()); Runtime.getRuntime() .addShutdownHook(new Thread(new RunProcessKiller(runProcess))); int exitCode = runProcess.run(true, args.toArray(new String[args.size()])); if (exitCode != 0) { throw new MojoExecutionException( "Application finished with non-zero exit code: " + exitCode); } } catch (Exception ex) { throw new MojoExecutionException("Could not exec java", ex); } }
@Test public void runJar() throws Exception { File target = new File("target"); File[] jarFiles = target.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.getName().endsWith(".jar"); } }); assertThat("Number of jars", jarFiles.length, equalTo(1)); Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); process.waitFor(5, TimeUnit.MINUTES); assertThat(process.exitValue(), equalTo(0)); String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); assertThat(output, containsString("Spring Boot Ant Example")); }
@Override protected void runWithForkedJvm(List<String> args) throws MojoExecutionException { try { RunProcess runProcess = new RunProcess(new JavaExecutable().toString()); Runtime.getRuntime() .addShutdownHook(new Thread(new RunProcessKiller(runProcess))); runProcess.run(true, args.toArray(new String[args.size()])); } catch (Exception ex) { throw new MojoExecutionException("Could not exec java", ex); } }
@Override protected void runWithForkedJvm(List<String> args) throws MojoExecutionException { try { new RunProcess(new JavaExecutable().toString()).run(true, args.toArray(new String[args.size()])); } catch (Exception ex) { throw new MojoExecutionException("Could not exec java", ex); } }
ForkProcessCommand(Command command) { super(new JavaExecutable().toString()); this.command = command; }