Skip to content

Commit ab22083

Browse files
committed
add findJavaExecutable
1 parent 47173e0 commit ab22083

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/test/java/smoketest/ant/SampleAntApplicationIT.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import org.junit.jupiter.api.Test;
2424

25-
2625
import org.springframework.util.FileCopyUtils;
2726

2827
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,13 +37,27 @@ class SampleAntApplicationIT {
3837
@Test
3938
void runJar() throws Exception {
4039
File libs = new File("build/ant/libs");
41-
ProcessBuilder processBuilder = new ProcessBuilder(new File(System.getProperty("java.home"), "bin/java").getAbsolutePath(),
42-
"-jar", "spring-boot-smoke-test-ant.jar");
40+
String javaExecutable = findJavaExecutable();
41+
ProcessBuilder processBuilder = new ProcessBuilder(javaExecutable, "-jar", "spring-boot-smoke-test-ant.jar");
4342
Process process = processBuilder.directory(libs).start();
4443
process.waitFor(5, TimeUnit.MINUTES);
4544
assertThat(process.exitValue()).isZero();
4645
String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
4746
assertThat(output).contains("Spring Boot Ant Example");
4847
}
4948

49+
private String findJavaExecutable() {
50+
// First try java.home system property
51+
String javaHome = System.getProperty("java.home");
52+
if (javaHome != null) {
53+
File javaExecutable = new File(javaHome, "bin/java");
54+
if (javaExecutable.exists() && javaExecutable.canExecute()) {
55+
return javaExecutable.getAbsolutePath();
56+
}
57+
}
58+
59+
// Fallback to PATH
60+
return "java";
61+
}
62+
5063
}

0 commit comments

Comments
 (0)