diff --git a/distribution/src/main/resources/bin/elasticsearch-plugin.bat b/distribution/src/main/resources/bin/elasticsearch-plugin.bat index 5604b57dbef..ba35ad1c214 100644 --- a/distribution/src/main/resources/bin/elasticsearch-plugin.bat +++ b/distribution/src/main/resources/bin/elasticsearch-plugin.bat @@ -2,7 +2,15 @@ SETLOCAL enabledelayedexpansion -if NOT DEFINED JAVA_HOME goto err +IF DEFINED JAVA_HOME ( + set JAVA=%JAVA_HOME%\bin\java.exe +) ELSE ( + FOR %%I IN (java.exe) DO set JAVA=%%~$PATH:I +) +IF NOT EXIST "%JAVA%" ( + ECHO Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME 1>&2 + EXIT /B 1 +) set SCRIPT_DIR=%~dp0 for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI @@ -48,15 +56,6 @@ GOTO loop SET HOSTNAME=%COMPUTERNAME% -"%JAVA_HOME%\bin\java" %ES_JAVA_OPTS% -Des.path.home="%ES_HOME%" !properties! -cp "%ES_HOME%/lib/*;" "org.elasticsearch.plugins.PluginCli" !args! -goto finally - - -:err -echo JAVA_HOME environment variable must be set! -pause - - -:finally +"%JAVA%" %ES_JAVA_OPTS% -Des.path.home="%ES_HOME%" !properties! -cp "%ES_HOME%/lib/*;" "org.elasticsearch.plugins.PluginCli" !args! ENDLOCAL diff --git a/distribution/src/main/resources/bin/elasticsearch.bat b/distribution/src/main/resources/bin/elasticsearch.bat index 9f1d871d0a2..37d7fc026a8 100644 --- a/distribution/src/main/resources/bin/elasticsearch.bat +++ b/distribution/src/main/resources/bin/elasticsearch.bat @@ -35,14 +35,14 @@ FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO ( SET current=%%A SET params='%%B' SET silent=N - + IF "!current!" == "-s" ( SET silent=Y ) IF "!current!" == "--silent" ( SET silent=Y - ) - + ) + IF "!silent!" == "Y" ( SET nopauseonerror=Y ) ELSE ( @@ -52,7 +52,7 @@ FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO ( SET newparams=!current! ) ) - + IF "x!params!" NEQ "x" ( GOTO loop ) @@ -79,6 +79,6 @@ IF ERRORLEVEL 1 ( EXIT /B %ERRORLEVEL% ) -"%JAVA_HOME%\bin\java" %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams! +"%JAVA%" %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams! ENDLOCAL diff --git a/distribution/src/main/resources/bin/elasticsearch.in.bat b/distribution/src/main/resources/bin/elasticsearch.in.bat index d6f1ef308bd..2d73ed2b57b 100644 --- a/distribution/src/main/resources/bin/elasticsearch.in.bat +++ b/distribution/src/main/resources/bin/elasticsearch.in.bat @@ -1,12 +1,15 @@ @echo off -if DEFINED JAVA_HOME goto cont +IF DEFINED JAVA_HOME ( + set JAVA=%JAVA_HOME%\bin\java.exe +) ELSE ( + FOR %%I IN (java.exe) DO set JAVA=%%~$PATH:I +) +IF NOT EXIST "%JAVA%" ( + ECHO Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME 1>&2 + EXIT /B 1 +) -:err -ECHO JAVA_HOME environment variable must be set! 1>&2 -EXIT /B 1 - -:cont set SCRIPT_DIR=%~dp0 for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI diff --git a/distribution/src/main/resources/bin/service.bat b/distribution/src/main/resources/bin/service.bat index 81b6c8a5df5..344782030ee 100644 --- a/distribution/src/main/resources/bin/service.bat +++ b/distribution/src/main/resources/bin/service.bat @@ -28,27 +28,38 @@ if %bad_env_var% == 1 ( ) rem end TODO: remove for Elasticsearch 6.x -if NOT DEFINED JAVA_HOME goto err +IF DEFINED JAVA_HOME ( + SET JAVA=%JAVA_HOME%\bin\java.exe +) ELSE ( + FOR %%I IN (java.exe) DO set JAVA=%%~$PATH:I +) +IF NOT EXIST "%JAVA%" ( + ECHO Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME 1>&2 + EXIT /B 1 +) +IF DEFINED JAVA_HOME GOTO :cont +IF NOT "%JAVA:~-13%" == "\bin\java.exe" ( + FOR /f "tokens=2 delims=[]" %%I IN ('dir %JAVA%') DO @set JAVA=%%I +) +IF "%JAVA:~-13%" == "\bin\java.exe" ( + SET JAVA_HOME=%JAVA:~0,-13% +) + +:cont if not "%CONF_FILE%" == "" goto conffileset set SCRIPT_DIR=%~dp0 for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI -rem Detect JVM version to figure out appropriate executable to use -if not exist "%JAVA_HOME%\bin\java.exe" ( -echo JAVA_HOME points to an invalid Java installation (no java.exe found in "%JAVA_HOME%"^). Exiting... -goto:eof -) - -"%JAVA_HOME%\bin\java" -Xmx50M -version > nul 2>&1 +"%JAVA%" -Xmx50M -version > nul 2>&1 if errorlevel 1 ( echo Warning: Could not start JVM to detect version, defaulting to x86: goto x86 ) -"%JAVA_HOME%\bin\java" -Xmx50M -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul: +"%JAVA%" -Xmx50M -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul: if errorlevel 1 goto x86 set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x64.exe