当我运行时where java
,输出是:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk-13.0.2\bin\java.exe
这两个程序都名为“java”,但默认情况下运行的是上面的程序。我怎样才能将默认值更改为下面的程序,以便当我输入java
(程序)时,它使用java
JDK 中的程序,而不是 Java SE 中的程序?
答案1
1)无需编辑任何%PATH%
系统变量:
使用|find "string"
...
>where java|find/i "jdk"
C:\Program Files\Java\jdk-13.0.2\bin\java.exe
以下是.bat
要查找和使用的一个文件...\jdk*\java.exe
@echo off && setlocal EnableDelayedExpansion
rem :: check *sdk\java.exe x86, 64 and W6432 variable ::
for %%i in (ProgramFiles,ProgramFiles(x86^),ProgramW6432
)do if /i defined %%~i for /f tokens^=* %%z in ('2^>nul ^^^< nul ^^^
where /r "!%%~i!" java.exe^|find "jdk"')do set "_java=%%~z" && goto=%:^)
rem :: one simple error message if jdk*\java was not found ::
echo=jdk*\java.exe was not found in %%path%% variable and nor in...
echo=%%ProgramFiles%% ^| %%ProgramFiles(x86)%% ^| ^%%ProgramW6432%%
<con: rem./ & timeout.exe /t -1 /nobreak & endlocal & goto=%:eof
%:^)
rem./ your "jdk*\bin\java.exe" = !_java!
<con: rem./ & "!_java!" -version 2>&1|find/v ")"
<con: rem./ & timeout.exe 5 & endlocal & goto=%:eof
2)编辑/更改%PATH%
系统变量:
1.从......中去除%PATH%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
2.添加C:\Program Files\Java\jdk-13.0.2\bin
3.去做1.&2.在您的命令行中:
set "variable" = %Variable: item 1 == item 2%
set "variable" = %Variable: item 1 == item 2%
set "PATH=%PATH:C:\Program Files (x86)\Common Files\Oracle\Java\javapath=C:\Program Files\Java\jdk-13.0.2\bin%"
其他资源: