Last active
February 29, 2016 07:32
-
-
Save darcyparker/7121448 to your computer and use it in GitHub Desktop.
Searches for latest JDK installed and sets %JAVA_HOME% to it. Useful for tools like ant which expect %JAVA_HOME% to be set to a JDK. This saves me time in having to reset %JAVA_HOME% after I update my JDK install.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM https://gist.github.com/darcyparker/7121448 | |
REM Searches for latest JDK and sets JAVA_HOME | |
REM Look up current version | |
for /f "usebackq tokens=2*" %%i in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit" /s ^| "%WINDIR%\system32\find.exe" "CurrentVersion"`) do set _jdkcurrentver=%%j | |
REM Look up JavaHome for current version | |
for /f "usebackq tokens=2*" %%i in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\%_jdkcurrentver%" /s ^| "%WINDIR%\system32\find.exe" "JavaHome"`) do set JAVA_HOME=%%j | |
echo JAVA_HOME=%JAVA_HOME% | |
set _jdkcurrentver= | |
setx JAVA_HOME "%JAVA_HOME%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, haven't tried it, but was going to ask