Skip to content

Use JAVA_HOME or java.exe in PATH like the Linux scripts do #18685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions distribution/src/main/resources/bin/elasticsearch-plugin.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions distribution/src/main/resources/bin/elasticsearch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -52,7 +52,7 @@ FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO (
SET newparams=!current!
)
)

IF "x!params!" NEQ "x" (
GOTO loop
)
Expand All @@ -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
15 changes: 9 additions & 6 deletions distribution/src/main/resources/bin/elasticsearch.in.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
@echo off

if DEFINED JAVA_HOME goto cont

:err
ECHO JAVA_HOME environment variable must be set! 1>&2
EXIT /B 1
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
)

:cont
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI

Expand Down
29 changes: 20 additions & 9 deletions distribution/src/main/resources/bin/service.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down