Skip to content

Commit

Permalink
Fix when setting long PATH environment variable
Browse files Browse the repository at this point in the history
Avoid using setx to append to the PATH environment variable as it will
truncate to 1024 characters. Instead, use SetEnvironmentVariable
in powershell.
  • Loading branch information
devinbileck committed Dec 15, 2018
1 parent 1cf18a6 commit 47c59f8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/install_java.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off

::Ensure we have administrative privileges in order to install files and set environment variables
:: Ensure we have administrative privileges in order to install files and set environment variables
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' == '0' (
::If no error is encountered, we have administrative privileges
Expand Down Expand Up @@ -30,7 +30,7 @@ if exist "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%" (

echo Downloading required files to %TEMP%
powershell -Command "Invoke-WebRequest %jdk_url% -OutFile $env:temp\%jdk_filename%.tar.gz"
::Download 7zip (command line version) in order to extract the tar.gz file since there is no native support in Windows
:: Download 7zip (command line version) in order to extract the tar.gz file since there is no native support in Windows
powershell -Command "Invoke-WebRequest https://www.7-zip.org/a/7za920.zip -OutFile $env:temp\7za920.zip"
powershell -Command "Expand-Archive $env:temp\7za920.zip -DestinationPath $env:temp\7za920 -Force"

Expand All @@ -49,8 +49,9 @@ del /Q %TEMP%\%jdk_filename%.tar.gz

:SetEnvVars
echo Setting environment variables
setx /M JAVA_HOME "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%"
powershell -Command "[Environment]::SetEnvironmentVariable('JAVA_HOME', '%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%', 'Machine')"
set java_bin=%%JAVA_HOME%%\bin
echo %PATH%|find /i "%java_bin%">nul || setx /M PATH "%PATH%;%java_bin%"
echo %PATH%|find /i "%java_bin%">nul || powershell -Command "[Environment]::SetEnvironmentVariable('PATH', '%PATH%;%java_bin%', 'Machine')"

echo Done!
pause

0 comments on commit 47c59f8

Please sign in to comment.