Skip to content

Commit

Permalink
TomEECliIT locate java binary using java.home
Browse files Browse the repository at this point in the history
this allows cases where $JAVA_HOME points to another JDK than the one in the $PATH
  • Loading branch information
jungm committed Nov 27, 2024
1 parent 08f5889 commit 42608f8
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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 +
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand All @@ -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;
}
}

0 comments on commit 42608f8

Please sign in to comment.