简体   繁体   中英

Cannot find java.exe

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 probably a path variable, but I have not been able to understand how to fix it, if that is the problem.

Thanks in advance.

First of all, the path that you provided ie C:\\ProgramData\\Oracle\\Java\\javapath\\java.exe doesn't appear to be correct. It should point to either JRE or JDK folder that you (probably) have in here:

C:\Program Files (x86)\Java\jdk1.8.0_25\bin

In there you should at least see the following files (and hence, the addition of this bin directory to your PATH variable in the env vars):

java.exe

javac.exe

javaw.exe

javap.exe

java.h.exe

java-rmi.exe

javadoc.exe

jarsigner.exe

jar.exe

If you don't see the files above, something is definitely wrong! Also, even if you were using JRE (not JDK), you should still have this bin folder present, where java.exe resides.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@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).

I had the same problem. Here's what worked for me: Go into your path variable and delete: C:\\ProgramData\\Oracle\\Java\\javapath\\ .
Then add a new one called: %JAVA_HOME\\bin
This post helped: java-path-is-not-pointing-to-sdk-path-in-windows

Edit: Sorry, I just noticed that this question was 3 years old.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM