From 71989128b9e402eab2131dc4a0486ffa1e730474 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Thu, 12 Mar 2015 18:22:02 -0400 Subject: [PATCH] NIFI-416: Applied change from Ricky Saltzer to favor JAVA_HOME environment variable over simple 'java' command if available and default java is set --- .../java/org/apache/nifi/bootstrap/RunNiFi.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/nifi/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java b/nifi/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java index f920860443..28a9b71028 100644 --- a/nifi/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java +++ b/nifi/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java @@ -65,6 +65,7 @@ import java.util.logging.Level; public class RunNiFi { public static final String DEFAULT_CONFIG_FILE = "./conf/bootstrap.conf"; public static final String DEFAULT_NIFI_PROPS_FILE = "./conf/nifi.properties"; + public static final String DEFAULT_JAVA_CMD = "java"; public static final String GRACEFUL_SHUTDOWN_PROP = "graceful.shutdown.seconds"; public static final String DEFAULT_GRACEFUL_SHUTDOWN_VALUE = "20"; @@ -675,8 +676,19 @@ public class RunNiFi { final String classPath = classPathBuilder.toString(); String javaCmd = props.get("java"); - if ( javaCmd == null ) { - javaCmd = "java"; + if (javaCmd == null) { + javaCmd = DEFAULT_JAVA_CMD; + } + if (javaCmd.equals(DEFAULT_JAVA_CMD)) { + String javaHome = System.getenv("JAVA_HOME"); + if (javaHome != null) { + String fileExtension = isWindows() ? ".exe" : ""; + File javaFile = new File(javaHome + File.separatorChar + "bin" + + File.separatorChar + "java" + fileExtension); + if (javaFile.exists() && javaFile.canExecute()) { + javaCmd = javaFile.getAbsolutePath(); + } + } } final NiFiListener listener = new NiFiListener();