From 42608f880822f5b9cf199ccef67fd521feb720cd Mon Sep 17 00:00:00 2001 From: Markus Jung Date: Wed, 27 Nov 2024 07:53:00 +0100 Subject: [PATCH] TomEECliIT locate java binary using java.home this allows cases where $JAVA_HOME points to another JDK than the one in the $PATH --- .../java/org/apache/tomee/TomEECliIT.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java b/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java index 453e21aa2b8..b850f344ca8 100644 --- a/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java +++ b/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java @@ -89,11 +89,11 @@ public boolean accept(File dir, String name) { }); final ProcessBuilder builder = new ProcessBuilder() - .command("java", "-cp", jar.getAbsolutePath() + File.pathSeparator + - tomee.getAbsolutePath() + File.separator + "lib" + File.separator + openejbCore[0] + File.pathSeparator + - tomee.getAbsolutePath() + File.separator + "lib" + File.separator + commonsCli[0] + File.pathSeparator + - tomee.getAbsolutePath() + File.separator + "lib" + File.separator + commonsLang[0], - "org.apache.openejb.cli.Bootstrap", "classloadertest"); + .command(getJavaBinaryPath(), "-cp", jar.getAbsolutePath() + File.pathSeparator + + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + openejbCore[0] + File.pathSeparator + + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + commonsCli[0] + File.pathSeparator + + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + commonsLang[0], + "org.apache.openejb.cli.Bootstrap", "classloadertest"); final Process start = builder.start(); start.waitFor(); @@ -133,7 +133,7 @@ public boolean accept(final File pathname) { } final ProcessBuilder builder = new ProcessBuilder() - .command("java", "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator + + .command(getJavaBinaryPath(), "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + "*", "org.apache.openejb.cli.Bootstrap", "classloadertest"); @@ -205,7 +205,7 @@ public boolean accept(File dir, String name) { }); final ProcessBuilder builder = new ProcessBuilder() - .command("java", "-cp", jar.getAbsolutePath() + File.pathSeparator + + .command(getJavaBinaryPath(), "-cp", jar.getAbsolutePath() + File.pathSeparator + jar2.getAbsolutePath() + File.pathSeparator + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + openejbCore[0] + File.pathSeparator + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + commonsCli[0] + File.pathSeparator + @@ -258,7 +258,7 @@ public boolean accept(final File pathname) { } final ProcessBuilder builder = new ProcessBuilder() - .command("java", "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator + + .command(getJavaBinaryPath(), "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + "*", "org.apache.openejb.cli.Bootstrap", "classloadertest2"); @@ -308,7 +308,7 @@ public boolean accept(final File pathname) { } final ProcessBuilder builder = new ProcessBuilder() - .command("java", "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator + + .command(getJavaBinaryPath(), "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator + tomee.getAbsolutePath() + File.separator + "lib" + File.separator + "*", "org.apache.openejb.cli.Bootstrap", "classloadertest2"); @@ -325,4 +325,13 @@ public void testIfClassloaderNotChange() throws Exception { new Bootstrap().main(new String[]{"cipher"}); assertEquals(originalClassLoader, Thread.currentThread().getContextClassLoader()); } + + protected String getJavaBinaryPath() { + String javaExecutable = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; + if (System.getProperty("os.name").startsWith("Win")) { + javaExecutable += ".exe"; + } + + return javaExecutable; + } }