Java 为 Eclipse 设置正确的 PATH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35881210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:13:26  来源:igfitidea点击:

Setting the correct PATH for Eclipse

javaeclipsepath

提问by TyngeOfTheGinge

I recently changed my path so I could follow along in the Head First Java book and I had Eclipse before. Now when I try to get onto Eclipse again it won't open because it says it can't find a JRE or JDK to use in my directory. I have moved the JDK file around. I have jdk1.8.0_60 downloaded. So how can I get Eclipse to open again?

我最近改变了我的路径,所以我可以在 Head First Java 书中继续学习,而且我之前使用过 Eclipse。现在,当我再次尝试进入 Eclipse 时,它​​不会打开,因为它说它在我的目录中找不到要使用的 JRE 或 JDK。我已经移动了 JDK 文件。我已经下载了 jdk1.8.0_60。那么我怎样才能让 Eclipse 再次打开呢?

采纳答案by Christian W

Like Abob said:

就像阿布说的

Eclipse doesn't consult the JAVA_HOMEvariable

Eclipse 不咨询JAVA_HOME变量

You should specify where Eclipse should find your JDK in the file eclipse.ini. Specifically, the following parameter (note that it is 2 separate lines in the ini file):

您应该指定 Eclipse 应该在文件中找到您的 JDK 的位置eclipse.ini。具体如下参数(注意是ini文件中的2行):

-vm
C:\Java\JDK.8\bin\javaw.exe

or wherever your javaw.exe happens to be.

或者你的 javaw.exe 碰巧在哪里。

Note:The format of the inifile is very particular; make sure to consult https://wiki.eclipse.org/Eclipse.inito ensure you get it exactly right.

注意:文件的格式ini很讲究;请务必查阅https://wiki.eclipse.org/Eclipse.ini以确保您完全正确。

回答by Abob

Go to System Properties > Advanced > Enviroment Variablesand look under System variables

System Properties > Advanced > Enviroment Variables看看下面System variables

First, create/set your JAVA_HOMEvariable

首先,创建/设置您的JAVA_HOME变量

Even though Eclipse doesn't consult the JAVA_HOMEvariable, it's still a good idea to set it. See How do I run Eclipse?for more information.

即使 Eclipse 不咨询该JAVA_HOME变量,设置它仍然是一个好主意。请参阅如何运行 Eclipse?想要查询更多的信息。

If you have not created and/or do not see JAVA_HOMEunder the list of System variables, do the following:

如果您尚未创建和/或未JAVA_HOME在 列表下看到System variables,请执行以下操作:

  1. Click New...at the very bottom
  2. For Variable name, type JAVA_HOMEexactly
  3. For Variable value, this could be different depending on what bits your computer and java are.
    • If both your computer and java are 64-bit, type C:\Program Files\Java\jdk1.8.0_60
    • If both your computer and java are 32-bit, type C:\Program Files\Java\jdk1.8.0_60
    • If your computer is 64-bit, but your java is 32-bit, type C:\Program Files (x86)\Java\jdk1.8.0_60
  1. 点击New...最底部
  2. 对于Variable name,请准确键入JAVA_HOME
  3. 对于Variable value,这可能会有所不同,具体取决于您的计算机和 Java 的位。
    • 如果您的计算机和 java 都是64 位,请键入C:\Program Files\Java\jdk1.8.0_60
    • 如果您的计算机和 java 都是32 位的,请键入C:\Program Files\Java\jdk1.8.0_60
    • 如果您的计算机是64 位的,而您的java 是32 位的,请键入C:\Program Files (x86)\Java\jdk1.8.0_60

If you have created and/or do see JAVA_HOME, do the following:

如果您已经创建和/或确实看到了JAVA_HOME,请执行以下操作:

  1. Click on the row under System variablesthat you see JAVA_HOMEin
  2. Click Edit...at the very bottom
  3. For Variable value, change it to what was stated in #3 above based on java's and your computer's bits. To repeat:
    • If both your computer and java are 64-bit, change it to C:\Program Files\Java\jdk1.8.0_60
    • If both your computer and java are 32-bit, change it to C:\Program Files\Java\jdk1.8.0_60
    • If your computer is 64-bit, but your java is 32-bit, change it to C:\Program Files (x86)\Java\jdk1.8.0_60
  1. 单击System variablesJAVA_HOME在下面看到的行
  2. 点击Edit...最底部
  3. 对于Variable value,根据 java 和您计算机的位将其更改为上面 #3 中所述的内容。重复:
    • 如果您的计算机和 java 都是64 位,请将其更改为C:\Program Files\Java\jdk1.8.0_60
    • 如果您的计算机和 java 都是32 位的,请将其更改为C:\Program Files\Java\jdk1.8.0_60
    • 如果您的计算机是64 位的,而您的java 是32 位的,请将其更改为C:\Program Files (x86)\Java\jdk1.8.0_60

Next, add to your PATHvariable

接下来,添加到您的PATH变量

  1. Click on the row under System variableswith PATHin it
  2. Click Edit...at the very bottom
  3. If you have a newer versionof windows:
    • Click New
    • Type in C:\Program Files (x86)\Java\jdk1.8.0_60ORC:\Program Files\Java\jdk1.8.0_60depending on the bits of your computer and java (see above ^).
    • Press Enterand Click Newagain.
    • Type in C:\Program Files (x86)\Java\jdk1.8.0_60\jreORC:\Program Files\Java\jdk1.8.0_60\jredepending on the bits of your computer and java (see above again ^).
    • Press Enterand press OKon all of the related windows
  4. If you have an older versionof windows
    • In the Variable valuetextbox (or something similar) drag the cursor all the way to the very end
    • Add a semicolon (;) if there isn't one already
    • C:\Program Files (x86)\Java\jdk1.8.0_60ORC:\Program Files\Java\jdk1.8.0_60
    • Add another semicolon (;)
    • C:\Program Files (x86)\Java\jdk1.8.0_60\jreORC:\Program Files\Java\jdk1.8.0_60\jre
  1. 点击下排System variablesPATH
  2. 点击Edit...最底部
  3. 如果您有较新版本的 Windows:
    • 点击 New
    • 根据您的计算机和 java 的位输入C:\Program Files (x86)\Java\jdk1.8.0_60ORC:\Program Files\Java\jdk1.8.0_60(见上文 ^)。
    • 再次按下Enter并单击New
    • 根据您的计算机和 java 的位输入C:\Program Files (x86)\Java\jdk1.8.0_60\jreORC:\Program Files\Java\jdk1.8.0_60\jre(再次参见上文 ^)。
    • 按下Enter并按下OK所有相关窗口
  4. 如果您有旧版本的 Windows
    • Variable value文本框(或类似的东西)中将光标一直拖到最后
    • ;如果还没有分号,请添加一个分号 ( )
    • C:\Program Files (x86)\Java\jdk1.8.0_60或者C:\Program Files\Java\jdk1.8.0_60
    • 添加另一个分号 ( ;)
    • C:\Program Files (x86)\Java\jdk1.8.0_60\jre或者C:\Program Files\Java\jdk1.8.0_60\jre

Changing eclipse.ini

改变 eclipse.ini

  1. Find your eclipse.inifile and copy-paste it in the same directory (should be named eclipse(1).ini)
  2. Rename eclipse.inito eclipse.ini.oldjust in case something goes wrong
  3. Rename eclipse(1).inito eclipse.ini
  4. Open your newly-renamed eclipse.iniand replace all of it with this:

    -startup
    plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
    --launcher.library
    plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
    -product
    org.eclipse.epp.package.java.product
    --launcher.defaultAction
    openFile
    --launcher.XXMaxPermSize
    256M
    -showsplash
    org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    --launcher.defaultAction
    openFile
    -vm
    C:\Program Files\Java\jdk1.8.0_60\bin\javaw.exe
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx1024m
    
  1. 找到您的eclipse.ini文件并将其复制粘贴到同一目录中(应命名为eclipse(1).ini
  2. 重命名eclipse.inieclipse.ini.old以防万一出现问题
  3. 重命名eclipse(1).inieclipse.ini
  4. 打开您新重命名的eclipse.ini并将其全部替换为:

    -startup
    plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
    --launcher.library
    plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
    -product
    org.eclipse.epp.package.java.product
    --launcher.defaultAction
    openFile
    --launcher.XXMaxPermSize
    256M
    -showsplash
    org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    --launcher.defaultAction
    openFile
    -vm
    C:\Program Files\Java\jdk1.8.0_60\bin\javaw.exe
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx1024m
    

XXMaxPermSizemay be deprecated, so it might not work. If eclipse still does not launch, do the following:

XXMaxPermSize可能会被弃用,所以它可能不起作用。如果 eclipse 仍然没有启动,请执行以下操作:

  1. Delete the newer eclipse.ini
  2. Rename eclipse.ini.oldto eclipse.ini
  3. Open command prompt
  4. type in eclipse -vm C:\Program Files (x86)\Java\jdk1.8.0_60\bin\javaw.exe
  1. 删除较新的 eclipse.ini
  2. 重命名eclipse.ini.oldeclipse.ini
  3. 打开命令提示符
  4. 输入 eclipse -vm C:\Program Files (x86)\Java\jdk1.8.0_60\bin\javaw.exe

If the problem remains

如果问题仍然存在

Try updating your eclipse and java to the latest version. 8u60 (1.8.0_60) is not the latest version of java. Sometimes, the latest version of java doesn't work with older versions of eclipse and vice versa. Otherwise, leave a comment if you're still having problems. You could also try a fresh reinstallation of Java.

尝试将 eclipse 和 java 更新到最新版本。8u60 ( 1.8.0_60) 不是最新版本的 java。有时,最新版本的 java 不适用于旧版本的 eclipse,反之亦然。否则,如果您仍然遇到问题,请发表评论。您也可以尝试重新安装 Java。

回答by cryptonkid

Eclipse folder has an initialization file which is used by eclipse on launch/Double click it is named as eclipse.ini. Add the following lines in eclipse.ini file. Where the vm defines the path of JVMwith which we want eclipse to use.

Eclipse 文件夹有一个初始化文件,eclipse 在启动/双击时使用它,它被命名为 eclipse.ini。在 eclipse.ini 文件中添加以下几行。其中 vm 定义了我们希望 eclipse 使用的 J VM的路径。

-vm
C:\Program Files\Java\jdk1.8\bin\javaw.exe

Make sure you have add the above lines separately and above the following line

确保您已单独添加以上行并在以下行上方

--launcher.appendVmargs
-vmargs

回答by Luis Solano

For me none worked. I compared my existing eclipse.iniwith a new one and started removing options and testing if eclipse worked.

对我来说没有工作。我将现有的eclipse.ini与新的进行了比较,并开始删除选项并测试 eclipse 是否有效。

The only option that prevented eclipse from starting was -XX:+UseParallelGC, so I removed it and voilá!

阻止 eclipse 启动的唯一选项是-XX:+UseParallelGC,所以我删除了它,瞧!

回答by vamsi

I am using Windows 8.1 environment. I had the same problem while running my first java program after installing Eclipse recently. I had installed java on d drive at d:\java. But Eclipse was looking at the default installation c:\programfiles\java. I did the following:

我正在使用 Windows 8.1 环境。我最近在安装 Eclipse 后运行我的第一个 java 程序时遇到了同样的问题。我已经在 d:\java 的 d 驱动器上安装了 java。但是 Eclipse 正在查看默认安装 c:\programfiles\java。我做了以下事情:

  1. Modified my eclipse.ini file and added the following after open:

    -vm
    d:\java\jdk1.8.0_161\bin 
    
  2. While creating the java program I have to unselect default build path and then select d:\java.

  1. 修改了我的 eclipse.ini 文件,打开后添加了以下内容:

    -vm
    d:\java\jdk1.8.0_161\bin 
    
  2. 在创建 java 程序时,我必须取消选择默认构建路径,然后选择 d:\java。

After this, the program ran well and got the hello world to work.

在此之后,程序运行良好并让 hello world 工作。

回答by Zorin

I have resolved this problem by adding or changing variables in environment variables. Go to Win7 -> My Computer - > Properties - > Advanced system settings -> environment Variables

我通过在环境变量中添加或更改变量解决了这个问题。进入Win7->我的电脑->属性->高级系统设置->环境变量

  1. If there is no variable JAVA_HOME, add it with value of variable, with route to folder where your JDK installed, for examle C:\Program Files\Java\jdk-11.0.2
  2. If there is no variable PATH or it have another value, change the value of variable to C:\Program Files\Java\jdk-11.0.2\bin or add variable PATH with this value
  1. 如果没有变量 JAVA_HOME,添加变量值为变量,路由到安装 JDK 的文件夹,例如 C:\Program Files\Java\jdk-11.0.2
  2. 如果没有变量PATH或者它有其他值,将变量的值更改为C:\Program Files\Java\jdk-11.0.2\bin或使用该值添加变量PATH

Good Luck

祝你好运

回答by Dilip shukla

There are working combinations of OS, JDK and Eclipse bitness. In my case, I was using a 64-bit JDK with a 32-bit Eclipse on a 64-bit OS. After downgrading the JDK to 32-bit, Eclipse started working.

有操作系统、JDK 和 Eclipse 位数的工作组合。就我而言,我在 64 位操作系统上使用 64 位 JDK 和 32 位 Eclipse。将 JDK 降级到 32 位后,Eclipse 开始工作。

Kindly use one of the following combinations.

请使用以下组合之一。

32-bit OS, 32-bit JDK, 32-bit Eclipse (32-bit only)

32 位操作系统、32 位 JDK、32 位 Eclipse(仅限 32 位)

64-bit OS, 32-bit JDK, 32-bit Eclipse

64 位操作系统、32 位 JDK、32 位 Eclipse

64-bit OS, 64-bit JDK, 64-bit Eclipse (64-bit only)

64 位操作系统、64 位 JDK、64 位 Eclipse(仅限 64 位)