-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_setup-java.cmd
More file actions
33 lines (26 loc) · 1.03 KB
/
Copy path_setup-java.cmd
File metadata and controls
33 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@echo off
setlocal EnableExtensions
set "RESOLVED_JAVA_HOME="
if defined JAVA_HOME if exist "%JAVA_HOME%\bin\javac.exe" (
set "RESOLVED_JAVA_HOME=%JAVA_HOME%"
)
if not defined RESOLVED_JAVA_HOME (
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command "$ErrorActionPreference='Stop'; $output = cmd /c 'java -XshowSettings:properties -version 2>&1'; $match = $output | Select-String 'java.home' | Select-Object -First 1; if ($match) { ($match.ToString().Split('=', 2)[1]).Trim() }"`) do (
set "RESOLVED_JAVA_HOME=%%I"
)
)
if not defined RESOLVED_JAVA_HOME (
echo Could not find a JDK automatically.
echo Install JDK 25 and make sure the ^`java^` command works in a new terminal.
exit /b 1
)
if not exist "%RESOLVED_JAVA_HOME%\bin\javac.exe" (
echo Detected Java directory is not a JDK: "%RESOLVED_JAVA_HOME%"
echo Point JAVA_HOME to the JDK root folder and try again.
exit /b 1
)
endlocal & (
set "JAVA_HOME=%RESOLVED_JAVA_HOME%"
set "PATH=%RESOLVED_JAVA_HOME%\bin;%PATH%"
)
exit /b 0