[java] "The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe"

I am on JDK 8u25 on Windows 8, and I am experiencing a problem with my Java installation. I can run javac perfectly fine, but running java produces this error message:

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

How do I fix this?


I think the problem has to do with my environment variables.

The important variables, as I have set them, are:

  • JAVA_HOMEC:\Program Files\Java\jdk1.8.0_25
  • CLASSPATH.;%JAVA_HOME%\lib
  • PATH<other paths omitted>;%JAVA_HOME%\bin

And their expansions, as viewed with set in cmd, are:

  • JAVA_HOMEC:\Program Files\Java\jdk1.8.0_25
  • CLASSPATH.;C:\Program Files\Java\jdk1.8.0_25\lib;%CLASSPATH%;
  • PATHC:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.6.0_45\bin;<other paths omitted>;C:\Program Files\Java\jdk1.8.0_25\bin

The full output of set can be viewed here.

This question is related to java environment-variables

The answer is


There must be two or more PATH variables. Try merging all of them into one using semi-colon (;)


If you're on a corporate PC that's fairly restricted by group policy, this might work....

Assuming that

  1. your Windows PATH includes C:\ProgramData\Oracle\Java\javapath
  2. you have JDK installed to C:\Program Files\Java\jdk1.8.0_60\bin

Then create the following text file mklink.bat and put it on your desktop:

rem mklink.bat
mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\jdk1.8.0_60\bin"
pause

Now right-click it and choose "Run as Administrator". Provide admin credentials. The script should report success. Now you can compile or run Java.


I had in PATH:

C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_92\bin;<others omitted>

I removed:

C:\ProgramData\Oracle\Java\javapath;

and that fixed the issue for me. java -version now gives details about the Java version, etc.


c:\ProgramData\Java\javapath is used for symlinks. You can of course add the full path to your Java Path to %PATH%, but equally you can create a symlink to the path to the above location.

  1. Open CMD as Administrator.
  2. Type mklink java.exe (full path to your Java.exe) eg

mklink java.exe "C:\Program Files\Java\jdk1.8.0_25\bin\java.exe"


I got the same after installing java8 from a non-permissioned account. To fix I simply reinstalled from admin user account. This created the quoted directory with file links to java exes.


This will solve all problems relating to Java and environment variables:

  1. Make your way to Windows' Environment Variables dialog.
  2. Under System variables, select the variable named Path. Click Edit...
  3. Remove the entry that looks like:

    C:\ProgramData\Oracle\Java\javapath
    
  4. Add the path of your JDK/JRE's bin folder.

  5. Don't forget to set JAVA_HOME.

I've got a similar problem I'm currently working on solving. I can't say this will solve your error since there may be issues with other software (which is my case with Eclipse Luna).

Java is using the path given in your PATH variable, which is,

  C:\ProgramData\Oracle\Java\javapath

Go to this folder (ProgramData is hidden, so unhide it if necessary) and right click on the java.exe symlink. You'll see in the Target field where it's looking for java.exe. It may be pointing to the java.exe file from your previous jdk1.6.0_45 install. Either paste in new shortcuts here or change the PATH setting as others have mentioned.

I've found that the Java installer doesn't change the javapath or update the system path, at least when going from 1.8 to 1.7. In my case changing the shortcuts only led to a problem with Eclipse on startup.

EDIT:----- After playing with javapath folder shortcuts it turns out you need symlinks, at least for Eclipse. See, Windows how to create directory symlink.

You don't need the /d switch for a file symlink,

  mklink java.exe "C:\Program Files\Java\jdk1.8.0_20\bin\java.exe"
  mklink javaw.exe "C:\Program Files\Java\jdk1.8.0_20\bin\javaw.exe"
  mklink javaws.exe "C:\Program Files\Java\jdk1.8.0_20\bin\javaws.exe"

This now works for me.


I had also similar problem where by I had to un-install JDK 1.8 and needed jdk 1.7. What i did was removed the symbolic links from the javapath and then imported the shortcuts of java, javaw, javaws from the bin directory to the javapath folder. However, I found some permission issues in the enterprise laptop where by I did not have the privilege to modify/ update this directory. I had given appropriate permission from the administrator and there by resolved it.


Why Oracle did such a poor way to point to java is beyond me. We solved this problem by creating a new link to the JDK

mklink /d C:\ProgramData\Oracle\Java\javapath "C:\Program Files\Java\jdk1.8.0_40\bin\"

The same would work for a JRE if that is all that is required.

This replaces the old symlinks in C:\ProgramData\Oracle\Java\javapath (if they existed previously)


Don't worry. Just uninstall jdk as well as jdk updates Before re installing jdk ,delete the oracle folder inside programData hidden folder in C:\ Then reinstall. Set the following,

JAVA_HOME
CLASSPATH
PATH
JRE_HOME ( is optional)

This problem exists when you upgrade from one version to another.because jdk is not automatically upgraded.

For the same you can change the environmental varibles. In system variables look for the PATH and add the jdk bin location in the front of the string(not at the back). Once you have done that check in CMD if "java" and "javac" works. if it works, again go to system variables. add "CLASSPATH" A the variable and set value " . c:\Program Files\Java\jdk1.8.0_91\lib;"


  1. Uninstall all JDKs installed on your computer from the Java Control Panel
  2. Search for C:\ProgramData\Oracle\Java and delete that directory and all files contained within. You can do this from the command line using rmdir /S C:\ProgramData\Oracle\Java
  3. Then search for C:\ProgramData\Oracle and delete the oracle folder. You can do this using rmdir /S C:\ProgramData\Oracle
  4. Now install JDK and set the path.

  5. Run the program.You won't find the same problem anymore.


<>\Common Files\Oracle\Java\javapath\ is now created as a junction, no symlinks anymore


Please remove "C:\ProgramData\Oracle\Java\javapath\java.exe" from the Path variable and add your jdk bin path. It will work.

In my case the I have removed the the above path and added my JDK path which is "C:\Program Files\Java\jdk1.8.0_221\bin"


For New version of Java JavaPath folder is located

64 bit OS

"C:\Program Files \Common Files\Oracle\Java\javapath\"

X86

"C:\Program Files(x86) \Common Files\Oracle\Java\javapath\"


This usually happens when you update the java, the easiest way to solve this is to just uninstall the JDK & then reinstall it. NOTE: This doesnt remove the path or classpath so no need to worry.


Updating the PATH Environment Variable

If you do not set the PATH variable, you need to specify the full path to the executable file every time you run it, such as:

C:\> "C:\Program Files\Java\jdk1.8.0\bin\javac" MyClass.java


It is useful to set the PATH variable permanently so it will persist after rebooting.
To set the PATH variable permanently, add the full path of the jdk1.8.0\bin directory to the PATH variable. Typically, this full path looks something like
C:\Program Files\Java\jdk1.8.0\bin.
Set the PATH variable as follows on Microsoft Windows:

  • Click Start, then Control Panel, then System.
  • Click Advanced, then Environment Variables.
  • Add the location of the bin folder of the JDK installation to the PATH variable in System Variables.
    The following is a typical value for the PATH variable:

    C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0\bin

    Note:

  • The PATH environment variable is a series of directories separated by semicolons (;) and is not case-sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.

  • You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored.

  • If you are not sure where to add the JDK path, append it.

The new path takes effect in each new command window you open after setting the PATH variable.


There are 2 versions of jdk in your PATH VARIABLE jdk1.6.0_45 and jdk1.8.0_25. Try removing the first one ie. jdk1.6.0_45 from the PATH


I got same error while running JAVA command. To resolve this, I moved the java path as the first entry in the path, and it resolved the issue. Please have look at this screenshot for reference:

enter image description here