NIFI-416: Applied change from Ricky Saltzer to favor JAVA_HOME environment variable over simple 'java' command if available and default java is set

This commit is contained in:
Mark Payne 2015-03-12 18:22:02 -04:00
parent 0f0d766707
commit 71989128b9
1 changed files with 14 additions and 2 deletions

View File

@ -65,6 +65,7 @@ import java.util.logging.Level;
public class RunNiFi { public class RunNiFi {
public static final String DEFAULT_CONFIG_FILE = "./conf/bootstrap.conf"; 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_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 GRACEFUL_SHUTDOWN_PROP = "graceful.shutdown.seconds";
public static final String DEFAULT_GRACEFUL_SHUTDOWN_VALUE = "20"; public static final String DEFAULT_GRACEFUL_SHUTDOWN_VALUE = "20";
@ -675,8 +676,19 @@ public class RunNiFi {
final String classPath = classPathBuilder.toString(); final String classPath = classPathBuilder.toString();
String javaCmd = props.get("java"); String javaCmd = props.get("java");
if ( javaCmd == null ) { if (javaCmd == null) {
javaCmd = "java"; 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(); final NiFiListener listener = new NiFiListener();