diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java index a90a4d30b4428..c6428b2f89b46 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java @@ -5,6 +5,7 @@ import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData; import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -18,6 +19,9 @@ public class DefaultJarLauncher implements JarArtifactLauncher { + private static final String JAVA_HOME_SYS = "java.home"; + private static final String JAVA_HOME_ENV = "JAVA_HOME"; + private int httpPort; private int httpsPort; private long waitTimeSeconds; @@ -45,7 +49,7 @@ public void start() throws IOException { System.setProperty("test.url", TestHTTPResourceManager.getUri()); List args = new ArrayList<>(); - args.add("java"); + args.add(determineJavaPath()); if (!argLine.isEmpty()) { args.addAll(argLine); } @@ -86,6 +90,26 @@ public void start() throws IOException { } + private String determineJavaPath() { + // try system property first - it will be the JAVA_HOME used by the current JVM + String home = System.getProperty(JAVA_HOME_SYS); + if (home == null) { + // No luck, somewhat a odd JVM not enforcing this property + // try with the JAVA_HOME environment variable + home = System.getenv(JAVA_HOME_ENV); + } + if (home != null) { + File javaHome = new File(home); + File file = new File(javaHome, "bin/java"); + if (file.exists()) { + return file.getAbsolutePath(); + } + } + + // just assume 'java' is on the system path + return "java"; + } + @Override public boolean listensOnSsl() { return isSsl;