我正在尝试让Eclipse v3.5 (Galileo)在我的计算机上重新运行-我以前运行过,没有问题,但现在我一直得到这个错误:

要运行Eclipse,必须提供Java运行时环境(JRE)或Java开发工具包(JDK)。在搜索以下位置后没有发现Java虚拟机: C: \ eclipse \ jre \ javaw.exe javaw.exe在当前路径

我刚刚重新安装了JDK和SDK。

我用的是Windows 7 (x64)。

这是怎么回事?我该怎么解决呢?

我不能运行任何ipconfig / tracert /或ping。


当前回答

我也遇到过这个问题。我的案例如下:

在文本:

HKEY_CURRENT_USER\Environment
    Path    REG_SZ    %JAVA_HOME%\bin;C:\ProgramFiles\nodejs

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    JAVA_HOME    REG_SZ    C:\ProgramFiles\Java\jdk
    Path    REG_EXPAND_SZ    C:\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\
WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Progra
m Files (x86)\Perforce;C:\ProgramFiles\010 Editor;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\ProgramFiles\
Git\cmd;C:\Program Files (x86)\Skype\Phone\

C:\Users\ssfang> echo %^JAVA_HOME% = "%^JAVA_HOME%" = %%JAVA_HOME%% %JAVA_HOME%
%JAVA_HOME% = "%^JAVA_HOME%" = %C:\ProgramFiles\Java\jdk% C:\ProgramFiles\Java\jdk

我发现他们的注册表值Path的类型是不同的,所以我用下面的命令检查路径是否有效:

C:\Users\ssfang> where node java
C:\ProgramFiles\nodejs\node.exe
INFO: Could not find "java".

因此,我通过以下命令(Setx)重置本地(当前用户)环境:

C:\Users\ssfang> setx PATH %^JAVA_HOME%\bin;"C:\ProgramFiles\nodejs"

SUCCESS: Specified value was saved.

C:\Users\ssfang> reg query HKEY_CURRENT_USER\Environment /v Path

HKEY_CURRENT_USER\Environment
    Path    REG_EXPAND_SZ    %JAVA_HOME%\bin;C:\ProgramFiles\nodejs

C:\Users\ssfang> where node java
C:\ProgramFiles\nodejs\node.exe
INFO: Could not find "java".

C:\Users\ssfang>echo %PATH%
C:\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Fi
les\Intel\DMIX;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Perforce;C:\ProgramFile
s\010 Editor;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\ProgramFiles\Git\cmd;C:\Program Files (x86)\Skype\
Phone\;%JAVA_HOME%\bin;C:\ProgramFiles\nodejs

但是,在当前流程中,它不能将这些更改传播到其他正在运行的流程。

但是,如果直接在“注册表编辑器”中修改用户环境变量,

those modifications to the environment variables do not result in immediate change. For example, if you start another Command Prompt after making the changes, the environment variables will reflect the previous (not the current) values. The changes do not take effect until you log off and then log back on. To effect these changes without having to log off, broadcast a WM_SETTINGCHANGE message to all windows in the system, so that any interested applications (such as Windows Explorer, Program Manager, Task Manager, Control Panel, and so forth) can perform an update.

详细信息请参见如何将环境变量传播到系统

在这里,我给出了一个powershell脚本来完成它:

# powershell -ExecutionPolicy ByPass -File
# Standard, inline approach: (i.e. behaviour you'd get when using & in Linux)
# START /B CMD /C CALL "foo.bat" [args [...]]
# powershell -ExecutionPolicy ByPass -WindowStyle Hidden -File myScript.ps1 


<#
Add-Type @'

public class CSharp
{
    public static void Method(object[] first, object[] second)
    {
        System.Console.WriteLine("Hello world");
    }
}
'@
$a = 1..4;
[string[]]$b = "a","b","c","d";
[CSharp]::Method($a, $b);
#>


<#

#http://stackoverflow.com/questions/16552801/how-do-i-conditionally-add-a-class-with-add-type-typedefinition-if-it-isnt-add

#Problem Add-Type : Cannot add type. The type name 'PInvoke.User32' already exists.

if (-not ("MyClass" -as [type])) {
    add-type @"
    public class MyClass { }
"@
}


p.s. there's no Remove-Type; see this answer for more on how to best work around this limitation:
http://stackoverflow.com/questions/3369662/can-you-remove-an-add-ed-type-in-powershell-again

I think it will be wanted when debugging.
It is much simpler to close a tab in Console and open new one in PowerShell_ISE.exe or close PowerShell.exe.

Or

Start-Job -ScriptBlock {
    param([uri]$url,$OutputDir)
    # download and save pages
    Invoke-RestMethod $url | Out-File "$OutputDir\$($url.Segments[-1])" -Force
} -ArgumentList $link,$OutputDir

#>
if (-not ([System.Management.Automation.PSTypeName]'PInvoke.Program').Type)
{
    $sig=@"
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;

// The global namespace is the "root" namespace: global::system will always refer to the .NET Framework namespace System.

///P/Invoke (Platform Invoke)
namespace PInvoke
{
    public static class User32
    {
        /// http://www.pinvoke.net/default.aspx/Constants/HWND.html
        // public const IntPtr HWND_BROADCAST = new IntPtr(0xffff);
        /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms725497(v=vs.85).aspx
        /// http://www.pinvoke.net/default.aspx/Constants/WM.html
        public const UInt32 WM_SETTINGCHANGE = 0x001A;

        // SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,    (LPARAM) "Environment", SMTO_ABORTIFHUNG,    5000, &dwReturnValue);

        /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644952(v=vs.85).aspx
        /// If the function succeeds, the return value is nonzero. 
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessageTimeout", SetLastError = true)]
        public static extern uint SendMessageTimeout(IntPtr hWnd, uint Msg, int wParam, string lParam, SendMessageTimeoutFlags fuFlags, uint uTimeout, out int lpdwResult);
    }

    [Flags]
    public enum SendMessageTimeoutFlags : uint
    {
        SMTO_NORMAL = 0x0,
        SMTO_BLOCK = 0x1,
        SMTO_ABORTIFHUNG = 0x2,
        SMTO_NOTIMEOUTIFNOTHUNG = 0x8,
        SMTO_ERRORONEXIT = 0x20
    }

    public class Program
    {
        public static void Main(string[] args)
        {
            //int innerPinvokeResult;
            //uint pinvokeResult = User32.SendMessageTimeout(User32.HWND_BROADCAST, User32.WM_SETTINGCHANGE, 0, "Environment", SendMessageTimeoutFlags.SMTO_NORMAL, 1000, out innerPinvokeResult);
            Console.WriteLine("Over!!!!!!!!!!!!!!!!!!!!!!!!!");
        }
    }
}
"@

    Add-Type -TypeDefinition $sig
}


## [PInvoke.Program]::Main([IntPtr]::Zero);

$innerPinvokeResult=[int]0
[PInvoke.User32]::SendMessageTimeout([IntPtr]0xffff, [PInvoke.User32]::WM_SETTINGCHANGE, 0, "Environment", [PInvoke.SendMessageTimeoutFlags]::SMTO_NORMAL, 1000, [ref]$innerPinvokeResult);

对于Setx Setx [/s [/u [] [/p]]]]] [/m]

/m Specifies to set the variable in the system environment. The default setting is the local environment

其他回答

别担心,我也被这个错误和致命的破坏,当我得到它,我是如此沮丧,甚至我是给离开一个android编程,但我得到了它,简单地首先复制这段代码,并粘贴在你的系统变量下路径…

C:\程序文件;C:\Winnt;C:\Winnt\System32;C:\程序 Files\Java\jre6\bin\javaw.exe

现在从你的路径复制“jre”文件夹,就像我在这个路径下有“jre”一样

            C:\Program Files\Java

并将其粘贴到eclipse文件夹中意味着放置eclipse.exe文件的位置。比如我在这个位置设置了日食

    F:\Softwares\LANGUAGES SOFTEARE\Android Setup\eclipse

所以在eclipse文件夹中粘贴jre文件夹。如果您有“jre6”,则将其重命名为“jre”....运行你的eclipse,你会得到解决方案…

   //<<<<<<<<<<<<<<----------------------------->>>>>>>>>>>>>>>>>>>                 

其他方案:2

如果上述步骤无法解决问题,请执行以下步骤

从您的Java路径(如C:\Program Files\Java\jre6*)复制文件夹“jre” 等,并将其粘贴到您的eclipse目录(Where is your eclipse 可用) 打开eclipse。ini文件。 像这样更改javaw.exe文件的目录

-vmF:\Softwares\LANGUAGES SOFTEARE\Android Setup\eclipse Indigo version 32 Bit\jre\bin/java .exe

现在,当你启动eclipse时,它将搜索javaw.exe,所以它将搜索eclipse.ini中的路径,因为它现在在同一个文件夹中,它将启动javaw.exe,它将开始工作。

如果你还有任何疑问,你可以再问一次,只要上我的个人资料,找到我的电子邮件id。因为我喜欢堆栈溢出论坛,它让我成为了一名程序员

Eclipse将在默认情况下尝试使用默认的“java.exe”(由PATH引用的第一个)启动。

要记住三件事:

"Installing" a JRE or a JDK can be as simple as unzipping or copying it from another computer: there is no special installation steps, and you can have as many different JVM versions (1.4, 5.0, 6.0...) as you want, "installed" (copied) almost anywhere on your disk. I would recommend to always run Eclipse with the lastest JRE possible (to benefit from the latest hotspot evolutions). You can: Reference that exact JRE path in your eclipse.ini. Copy any JRE of your in your <eclipse>/jre directory. In both cases, no PATH to update. The JVM you will reference within your Eclipse session is not always the one used for launching Eclipse because: You only need a JRE to launch Eclipse, but once Eclipse launched, you should register a JDK for your projects (especially for Java sources and debugging purposes, also in theory for compilation but Eclipse has its own Java compiler) Note: You could register just a JRE within Eclipse because it is enough to run your program, but again a JDK will allow for more operations. Even though the default registered Java in Eclipse is the one used to launch the session, you can want to register an older SDK (including a non-Sun one) in order to run/debug your programs with a JRE similar to the one which will actually be used in production.


2012年6月,jmbertucci评论道:

我运行的是64位的Windows 7,并且安装了32位的JRE。 我下载了一个64位的Eclipse 64位JRE。 因为我没有64位JRE,所以它抛出了错误,这是有道理的。 我转到Java手动安装页面(不像你想的那样直接访问),安装了64位版本。参见“适用于所有操作系统的Java下载”。 这就是我所需要的。


2016年4月:史蒂夫·梅恩在评论中补充道:

我必须编辑eclipse.ini文件以引用正确的Java路径- 当Eclipse .ini中有值时,Eclipse根本不使用环境PATH。

在eclipse文件夹中创建一个批处理文件,并在其中写入:

eclipse -vm C:\Sun\SDK\jdk\jre\bin\javaw.exe

看到 http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F

进入Eclipse—>Windows—>Preferences 然后进入“已安装JRE” 然后点击添加,然后添加新的JDK路径(JDK安装在你机器上的路径)

然后点击确定

它应该映射到eclipse和work。

注意:只有你映射的最新版本的JDK才会显示在已安装的JRE中,类型为标准,名称为默认。

谢谢。

JDK不会在默认路径下安装JVM。

除非您像ant一样需要外部工具来运行,否则非jdk就足以让Eclipse运行。安装这样的JVM最简单的方法是访问http://java.com,让它安装它想安装的任何东西。

然后再次双击Eclipse二进制文件。