package net.serenitybdd.integration.utils;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static net.serenitybdd.integration.utils.Nulls.coalesce;

public class CommandLineTools {
    public static Path java() {
        Path javaBin = Paths.get(coalesce(
                System.getenv("JENKINS_JAVA_HOME"),
                System.getenv("JAVA_HOME"),
                System.getProperty("java.home")
        )).resolve("bin/java");

        if (! Files.isExecutable(javaBin)) {
            throw new RuntimeException("'java' executable not found. Please set the JAVA_HOME env variable to point to your Java home directory.");
        }

        return javaBin;
    }
}

@@ -267,19 +267,20 @@
 ath java
-Bin
+Home
  = Paths
@@ -452,29 +452,294 @@
   ))
-.resolve(%22bin/java%22);
+;%0A        %0A        Path javaBin = null;%0A        if (Files.exists(javaHome.resolve(%22bin/java%22))) %7B%0A        %09javaBin = javaHome.resolve(%22bin/java%22);%0A        %7D%0A        else if (Files.exists(javaHome.resolve(%22bin/java.exe%22))) %7B%0A        %09javaBin = javaHome.resolve(%22bin/java.exe%22);%0A        %7D
 %0A%0A  

Fix for #332