简体   繁体   English

“系统找不到文件 C:\ProgramData\Oracle\Java\javapath\java.exe”

[英]"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.我在 Windows 8 上使用 JDK 8u25,我在安装 Java 时遇到问题。 I can run javac perfectly fine, but running java produces this error message:我可以完美地运行javac ,但运行java会产生以下错误消息:

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 JAVA_HOMEC:\Program Files\Java\jdk1.8.0_25
  • CLASSPATH.;%JAVA_HOME%\lib CLASSPATH - .;%JAVA_HOME%\lib
  • PATH<other paths omitted>;%JAVA_HOME%\bin PATH<other paths omitted>;%JAVA_HOME%\bin

And their expansions, as viewed with set in cmd, are:从 cmd 中的set来看,它们的扩展是:

  • JAVA_HOMEC:\Program Files\Java\jdk1.8.0_25 JAVA_HOMEC:\Program Files\Java\jdk1.8.0_25
  • CLASSPATH.;C:\Program Files\Java\jdk1.8.0_25\lib;%CLASSPATH%;类路径 - .;C:\Program Files\Java\jdk1.8.0_25\lib;%CLASSPATH%; 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 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 .完整的set可以在这里查看。

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).我不能说这会解决您的错误,因为其他软件可能存在问题(我的 Eclipse Luna 就是这种情况)。

Java is using the path given in your PATH variable, which is, Java 正在使用 PATH 变量中给出的路径,即,

  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.转到此文件夹(ProgramData 已隐藏,因此如有必要,请取消隐藏它)并右键单击 java.exe 符号链接。 You'll see in the Target field where it's looking for java.exe.您将在目标字段中看到它正在寻找 java.exe。 It may be pointing to the java.exe file from your previous jdk1.6.0_45 install.它可能指向您之前安装的 jdk1.6.0_45 中的 java.exe 文件。 Either paste in new shortcuts here or change the PATH setting as others have mentioned.要么在此处粘贴新的快捷方式,要么像其他人提到的那样更改 PATH 设置。

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.我发现 Java 安装程序不会更改 javapath 或更新系统路径,至少在从 1.8 到 1.7 时是这样。 In my case changing the shortcuts only led to a problem with Eclipse on startup.就我而言,更改快捷方式只会导致 Eclipse 在启动时出现问题。

EDIT:----- After playing with javapath folder shortcuts it turns out you need symlinks, at least for Eclipse.编辑:----- 在使用 javapath 文件夹快捷方式后,结果证明您需要符号链接,至少对于 Eclipse。 See, Windows how to create directory symlink .看, Windows 如何创建目录符号链接

You don't need the /d switch for a file symlink,您不需要文件符号链接的 /d 开关,

  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.这现在对我有用。

Why Oracle did such a poor way to point to java is beyond me.为什么 Oracle 以如此糟糕的方式指向 java 是我无法理解的。 We solved this problem by creating a new link to the JDK我们通过创建一个指向 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.如果只需要这些,同样适用于 JRE。

This replaces the old symlinks in C:\\ProgramData\\Oracle\\Java\\javapath (if they existed previously)这将替换C:\\ProgramData\\Oracle\\Java\\javapath的旧符号链接(如果它们以前存在)

I had in PATH :我在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. java -version现在提供有关 Java 版本等的详细信息。

This will solve all problems relating to Java and environment variables:这将解决与 Java 和环境变量相关的所有问题:

  1. Make your way to Windows' Environment Variables dialog .进入 Windows 的环境变量对话框
  2. Under System variables , select the variable named Path .系统变量下,选择名为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.添加 JDK/JRE 的bin文件夹的路径。

  5. Don't forget to set JAVA_HOME .不要忘记设置JAVA_HOME

Updating the PATH Environment Variable更新 PATH 环境变量

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:如果不设置PATH变量,则每次运行时都需要指定可执行文件的完整路径,如:

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.永久设置 PATH 变量很有用,因此它会在重新启动后保持不变。
To set the PATH variable permanently, add the full path of the jdk1.8.0\\bin directory to the PATH variable.要永久设置 PATH 变量,请将 jdk1.8.0\\bin 目录的完整路径添加到 PATH 变量中。 Typically, this full path looks something like通常,这个完整路径看起来像
C:\\Program Files\\Java\\jdk1.8.0\\bin . C:\\Program Files\\Java\\jdk1.8.0\\bin
Set the PATH variable as follows on Microsoft Windows:在 Microsoft Windows 上按如下方式设置 PATH 变量:

  • 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.在系统变量中的PATH变量中添加JDK安装的bin文件夹的位置。
    The following is a typical value for the PATH variable:以下是 PATH 变量的典型值:

    C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\Program Files\\Java\\jdk1.8.0\\bin 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. PATH 环境变量是一系列由分号 (;) 分隔的目录,不区分大小写。 Microsoft Windows looks for programs in the PATH directories in order, from left to right. Microsoft Windows 按从左到右的顺序在 PATH 目录中查找程序。

  • You should only have one bin directory for a JDK in the path at a time.您一次应该在路径中只有一个 JDK 的 bin 目录。 Those following the first instance are ignored.那些跟随第一个实例的将被忽略。

  • If you are not sure where to add the JDK path, append it.如果您不确定在哪里添加 JDK 路径,请附加它。

The new path takes effect in each new command window you open after setting the PATH variable.设置 PATH 变量后,新路径在您打开的每个新命令窗口中生效。

There are 2 versions of jdk in your PATH VARIABLE jdk1.6.0_45 and jdk1.8.0_25 .您的PATH VARIABLE jdk1.6.0_45jdk1.8.0_25有 2 个版本的 jdk。 Try removing the first one ie.尝试删除第一个即。 jdk1.6.0_45 from the PATH来自PATH jdk1.6.0_45

If you're on a corporate PC that's fairly restricted by group policy, this might work....如果您使用的是受组策略相当限制的公司 PC,这可能会奏效....

Assuming that假如说

  1. your Windows PATH includes C:\\ProgramData\\Oracle\\Java\\javapath您的 Windows PATH包括C:\\ProgramData\\Oracle\\Java\\javapath
  2. you have JDK installed to C:\\Program Files\\Java\\jdk1.8.0_60\\bin您已将 JDK 安装到C:\\Program Files\\Java\\jdk1.8.0_60\\bin

Then create the following text file mklink.bat and put it on your desktop:然后创建以下文本文件mklink.bat并将其放在您的桌面上:

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.现在您可以编译或运行 Java。

This problem exists when you upgrade from one version to another.because jdk is not automatically upgraded.从一个版本升级到另一个版本时会出现这个问题,因为jdk不会自动升级。

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).在系统变量中查找PATH并在字符串的前面(而不是后面)添加 jdk bin 位置。 Once you have done that check in CMD if " java " and " javac " works.如果“ java ”和“ javac ”有效,则在CMD中完成该检查后。 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; "添加“ CLASSPATH ”A变量和设置值“ .c:\\Program Files\\Java\\jdk1.8.0_91\\lib;

This usually happens when you update the java, the easiest way to solve this is to just uninstall the JDK & then reinstall it.这通常发生在您更新 java 时,解决此问题的最简单方法是卸载 JDK 然后重新安装它。 NOTE: This doesnt remove the path or classpath so no need to worry.注意:这不会删除路径或类路径,因此无需担心。

  1. Uninstall all JDKs installed on your computer from the Java Control Panel从 Java 控制面板卸载计算机上安装的所有 JDK
  2. Search for C:\\ProgramData\\Oracle\\Java and delete that directory and all files contained within.搜索C:\\ProgramData\\Oracle\\Java并删除该目录和其中包含的所有文件。 You can do this from the command line using rmdir /SC:\\ProgramData\\Oracle\\Java您可以使用rmdir /SC:\\ProgramData\\Oracle\\Java从命令行执行此操作
  3. Then search for C:\\ProgramData\\Oracle and delete the oracle folder.然后搜索 C:\\ProgramData\\Oracle 并删除 oracle 文件夹。 You can do this using rmdir /SC:\\ProgramData\\Oracle您可以使用rmdir /SC:\\ProgramData\\Oracle执行此操作
  4. Now install JDK and set the path.现在安装JDK并设置路径。

  5. Run the program.You won't find the same problem anymore.运行程序。你不会再发现同样的问题了。

I got same error while running JAVA command.我在运行 JAVA 命令时遇到了同样的错误。 To resolve this, I moved the java path as the first entry in the path, and it resolved the issue.为了解决这个问题,我将 java 路径作为路径中的第一个条目,它解决了这个问题。 Please have look at this screenshot for reference:请查看此屏幕截图以供参考:

在此处输入图片说明

There must be two or more PATH variables.必须有两个或多个 PATH 变量。 Try merging all of them into one using semi-colon (;)尝试使用分号 (;)

I got the same after installing java8 from a non-permissioned account.从未经许可的帐户安装 java8 后,我得到了相同的结果。 To fix I simply reinstalled from admin user account.要修复我只是从管理员用户帐户重新安装。 This created the quoted directory with file links to java exes.这创建了带有指向 java exe 的文件链接的引用目录。

I had also similar problem where by I had to un-install JDK 1.8 and needed jdk 1.7.我也有类似的问题,我不得不卸载 JDK 1.8 并需要 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.我所做的是从javapath中删除符号链接,然后将java、javaw、javaws的快捷方式从bin目录导入到javapath文件夹中。 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.我已经从管理员那里获得了适当的许可,并在那里解决了它。

c:\\ProgramData\\Java\\javapath is used for symlinks. c:\\ProgramData\\Java\\javapath用于符号链接。 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.您当然可以将 Java 路径的完整路径添加到%PATH% ,但同样您可以创建指向上述位置路径的符号链接。

  1. Open CMD as Administrator.以管理员身份打开CMD
  2. Type mklink java.exe (full path to your Java.exe) eg键入mklink java.exemklink java.exe完整路径),例如

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

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.只需卸载jdk以及jdk更新即可在重新安装jdk之前,删除C:\\中programData隐藏文件夹中的oracle文件夹,然后重新安装。 Set the following,设置以下,

JAVA_HOME
CLASSPATH
PATH
JRE_HOME ( is optional)

Please remove "C:\\ProgramData\\Oracle\\Java\\javapath\\java.exe" from the Path variable and add your jdk bin path.请从 Path 变量中删除“C:\\ProgramData\\Oracle\\Java\\javapath\\java.exe”并添加您的 jdk bin 路径。 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"就我而言,我已经删除了上述路径并添加了我的 JDK 路径,即“C:\\Program Files\\Java\\jdk1.8.0_221\\bin”

For New version of Java JavaPath folder is located对于新版本的 Java JavaPath 文件夹位于

64 bit OS 64位操作系统

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

X86 X86

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

<>\\Common Files\\Oracle\\Java\\javapath\\ 现在被创建为一个结点,不再有符号链接

This will solve all problems relating to Java and environment variables:这将解决与 Java 和环境变量相关的所有问题:

Make your way to Windows' Environment Variables dialog.进入 Windows 的环境变量对话框。 Under System variables, select the variable named Path.在系统变量下,select 名为 Path 的变量。 Click Edit... Remove the entry that looks like:单击编辑...删除如下所示的条目:

C:\ProgramData\Oracle\Java\javapath Add the path of your JDK/JRE's bin folder. C:\ProgramData\Oracle\Java\javapath 添加 JDK/JRE 的 bin 文件夹的路径。

Don't forget to set JAVA_HOME.不要忘记设置 JAVA_HOME。

This helped me.......:-)这对我有帮助....... :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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