Use java from path if JAVA_HOME is not set
This commit adds support to the Windows scripts for finding java.exe via the path if JAVA_HOME is not set. Relates #18685
This commit is contained in:
parent
d55f719f8a
commit
92c6d78d4a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue