Skip to content

Commit

Permalink
Remove support for JAVA_HOME (#69149)
Browse files Browse the repository at this point in the history
This commit removes support for JAVA_HOME. As we previously deprecated
usage of JAVA_HOME to override the path for the JDK, this commit follows
up by removing support for JAVA_HOME. Note that we do not treat
JAVA_HOME being set as a failure, as it is perfectly reasonable for a
user to have JAVA_HOME configured at the system level.
  • Loading branch information
jasontedor authored Feb 18, 2021
1 parent 5341a8c commit d3ac7c9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 44 deletions.
10 changes: 5 additions & 5 deletions distribution/src/bin/elasticsearch-env
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ ES_CLASSPATH="$ES_HOME/lib/*"
if [ ! -z "$ES_JAVA_HOME" ]; then
JAVA="$ES_JAVA_HOME/bin/java"
JAVA_TYPE="ES_JAVA_HOME"
elif [ ! -z "$JAVA_HOME" ]; then
# fallback to JAVA_HOME
echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2
JAVA="$JAVA_HOME/bin/java"
JAVA_TYPE="JAVA_HOME"
else
# use the bundled JDK (default)
if [ "$(uname -s)" = "Darwin" ]; then
Expand All @@ -66,6 +61,11 @@ if [ ! -z "$JAVA_TOOL_OPTIONS" ]; then
unset JAVA_TOOL_OPTIONS
fi

# warn that we are not observing the value of JAVA_HOME
if [ ! -z "$JAVA_HOME" ]; then
echo "warning: ignoring JAVA_HOME=$JAVA_HOME; using $JAVA_TYPE" >&2
fi

# JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
# warn them that we are not observing the value of $JAVA_OPTS
if [ ! -z "$JAVA_OPTS" ]; then
Expand Down
15 changes: 7 additions & 8 deletions distribution/src/bin/elasticsearch-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@ if "%ES_BUNDLED_JDK%" == "false" (

cd /d "%ES_HOME%"

rem now set the path to java, pass "nojava" arg to skip setting JAVA_HOME and JAVA
rem now set the path to java, pass "nojava" arg to skip setting ES_JAVA_HOME and JAVA
if "%1" == "nojava" (
exit /b
)

rem comparing to empty string makes this equivalent to bash -v check on env var
rem and allows to effectively force use of the bundled jdk when launching ES
rem by setting JAVA_HOME=
rem by setting ES_JAVA_HOME=
if defined ES_JAVA_HOME (
set JAVA="%ES_JAVA_HOME%\bin\java.exe"
set JAVA_TYPE=ES_JAVA_HOME
) else if defined JAVA_HOME (
rem fallback to JAVA_HOME
echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2
set JAVA="%JAVA_HOME%\bin\java.exe"
set "ES_JAVA_HOME=%JAVA_HOME%"
set JAVA_TYPE=JAVA_HOME
) else (
rem use the bundled JDK (default)
set JAVA="%ES_HOME%\jdk\bin\java.exe"
Expand All @@ -70,6 +64,11 @@ if defined JAVA_TOOL_OPTIONS (
set JAVA_TOOL_OPTIONS=
)

rem warn that we are not observing the value of $JAVA_HOME
if defined JAVA_HOME (
echo warning: ignoring JAVA_HOME=%JAVA_HOME%; using %JAVA_TYPE% >&2
)

rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
rem warn them that we are not observing the value of %JAVA_OPTS%
if defined JAVA_OPTS (
Expand Down
14 changes: 14 additions & 0 deletions docs/reference/migration/migrate_8_0/packaging.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ Use Java 11 or higher. Attempts to run {es} 8.0 using earlier Java versions will
fail.
====
//end::notable-breaking-changes[]

//tag::notable-breaking-changes[]
.JAVA_HOME is no longer supported.
[%collapsible]
====
*Details* +
`JAVA_HOME` is no longer supported to set the path for the JDK. Instead, use
the bundled JDK (preferable), or set `ES_JAVA_HOME`.
*Impact* +
Use the bundled JDK (preferable), or set `ES_JAVA_HOME`. `JAVA_HOME` will be
ignored.
====
//end::notable-breaking-changes[]
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ public void test51EsJavaHomeOverride() throws Exception {
assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(systemJavaHome1));
}

public void test51JavaHomeOverride() throws Exception {
public void test51JavaHomeIgnored() throws Exception {
assumeTrue(distribution().hasJdk);
Platforms.onLinux(() -> {
String systemJavaHome1 = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
sh.getEnv().put("JAVA_HOME", systemJavaHome1);
Expand All @@ -163,40 +164,15 @@ public void test51JavaHomeOverride() throws Exception {

final Installation.Executables bin = installation.executables();
final Result runResult = sh.run(bin.elasticsearch.toString() + " -V");
assertThat(runResult.stderr, containsString("warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME"));
assertThat(runResult.stderr, containsString("warning: ignoring JAVA_HOME=" + systemJavaHome + "; using bundled JDK"));

startElasticsearch();
ServerUtils.runElasticsearchTests();
stopElasticsearch();

String systemJavaHome1 = sh.getEnv().get("JAVA_HOME");
assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(systemJavaHome1));
}

public void test51EsJavaHomeOverrideOverridesJavaHome() throws Exception {
Platforms.onLinux(() -> {
String systemJavaHome1 = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
sh.getEnv().put("ES_JAVA_HOME", systemJavaHome1);
// deliberately set to a location that does not exist, if ES_JAVA_HOME takes precedence this is ignored
sh.getEnv().put("JAVA_HOME", "doesnotexist");
});
Platforms.onWindows(() -> {
final String systemJavaHome1 = sh.run("$Env:SYSTEM_JAVA_HOME").stdout.trim();
sh.getEnv().put("ES_JAVA_HOME", systemJavaHome1);
// deliberately set to a location that does not exist, if ES_JAVA_HOME takes precedence this is ignored
sh.getEnv().put("JAVA_HOME", "doesnotexist");
});

final Installation.Executables bin = installation.executables();
final Result runResult = sh.run(bin.elasticsearch.toString() + " -V");
assertThat(runResult.stderr, not(containsString("warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME")));

startElasticsearch();
ServerUtils.runElasticsearchTests();
stopElasticsearch();

String systemJavaHome1 = sh.getEnv().get("ES_JAVA_HOME");
assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(systemJavaHome1));
// if the JDK started with the bundled JDK then we know that JAVA_HOME was ignored
String bundledJdk = installation.bundledJdk.toString();
assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(bundledJdk));
}

public void test52BundledJdkRemoved() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ private Result runScriptIgnoreExitCode(String[] command) {
setWorkingDirectory(builder, workingDirectory);
}
builder.environment().keySet().remove("ES_JAVA_HOME"); // start with a fresh environment
builder.environment().keySet().remove("JAVA_HOME");
for (Map.Entry<String, String> entry : env.entrySet()) {
builder.environment().put(entry.getKey(), entry.getValue());
}
Expand Down

0 comments on commit d3ac7c9

Please sign in to comment.