Cannot find java.exe

前端 未结 3 1661
一个人的身影
一个人的身影 2021-01-27 11:22

I am trying to launch a .bat file but I get the error

System cannot find the file C:\\ProgramData\\Oracle\\Java\\javapath\\java.exe

I understand that this is pro

3条回答
  •  不要未来只要你来
    2021-01-27 11:51

    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    @ECHO OFF
    
    :: Export java settings from registry to a temporary file
    START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft" 
    
    
    if not exist "%Temp%\java.reg" (
        START /W REGEDIT /E %Temp%\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft"
    )
    
    
    
    if not exist "%Temp%\java.reg" (
        echo java not installed 
        exit /b 1
    )
    
    
    
    :: Find java location
    FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%\java.reg ^| FIND "INSTALLDIR"') DO SET "JAVA_HOME=%%B"
    SET "JAVA_HOME=%JAVA_HOME:"=%"
    SET "JAVA_HOME=%JAVA_HOME:\\=\%"
    ::SET JAVA_HOME
    set "java=%java_home%\bin\java.exe"
    "%java%" -version
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    

    Try this to see if you can automatically can detect the java location.And if it's work you can put this at the beginning of your script and use %java% in your script (though it will decrease the performance).

提交回复
热议问题