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
Setting the correct PATH for Eclipse
提问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
Eclipse doesn't consult the
JAVA_HOME
variable
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 ini
file 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 Variables
and look under System variables
去System Properties > Advanced > Enviroment Variables
看看下面System variables
First, create/set your JAVA_HOME
variable
首先,创建/设置您的JAVA_HOME
变量
Even though Eclipse doesn't consult the JAVA_HOME
variable, 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_HOME
under the list of System variables
, do the following:
如果您尚未创建和/或未JAVA_HOME
在 列表下看到System variables
,请执行以下操作:
- Click
New...
at the very bottom - For
Variable name
, typeJAVA_HOME
exactly - 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
- If both your computer and java are 64-bit, type
- 点击
New...
最底部 - 对于
Variable name
,请准确键入JAVA_HOME
- 对于
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
- 如果您的计算机和 java 都是64 位,请键入
If you have created and/or do see JAVA_HOME
, do the following:
如果您已经创建和/或确实看到了JAVA_HOME
,请执行以下操作:
- Click on the row under
System variables
that you seeJAVA_HOME
in - Click
Edit...
at the very bottom - 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
- If both your computer and java are 64-bit, change it to
- 单击
System variables
您JAVA_HOME
在下面看到的行 - 点击
Edit...
最底部 - 对于
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
- 如果您的计算机和 java 都是64 位,请将其更改为
Next, add to your PATH
variable
接下来,添加到您的PATH
变量
- Click on the row under
System variables
withPATH
in it - Click
Edit...
at the very bottom - If you have a newer versionof windows:
- Click
New
- Type in
C:\Program Files (x86)\Java\jdk1.8.0_60
ORC:\Program Files\Java\jdk1.8.0_60
depending on the bits of your computer and java (see above ^). - Press
Enter
and ClickNew
again. - Type in
C:\Program Files (x86)\Java\jdk1.8.0_60\jre
ORC:\Program Files\Java\jdk1.8.0_60\jre
depending on the bits of your computer and java (see above again ^). - Press
Enter
and pressOK
on all of the related windows
- Click
- If you have an older versionof windows
- In the
Variable value
textbox (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_60
ORC:\Program Files\Java\jdk1.8.0_60
- Add another semicolon (
;
) C:\Program Files (x86)\Java\jdk1.8.0_60\jre
ORC:\Program Files\Java\jdk1.8.0_60\jre
- In the
- 点击下排
System variables
用PATH
它 - 点击
Edit...
最底部 - 如果您有较新版本的 Windows:
- 点击
New
- 根据您的计算机和 java 的位输入
C:\Program Files (x86)\Java\jdk1.8.0_60
ORC:\Program Files\Java\jdk1.8.0_60
(见上文 ^)。 - 再次按下
Enter
并单击New
。 - 根据您的计算机和 java 的位输入
C:\Program Files (x86)\Java\jdk1.8.0_60\jre
ORC:\Program Files\Java\jdk1.8.0_60\jre
(再次参见上文 ^)。 - 按下
Enter
并按下OK
所有相关窗口
- 点击
- 如果您有旧版本的 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
- Find your
eclipse.ini
file and copy-paste it in the same directory (should be namedeclipse(1).ini
) - Rename
eclipse.ini
toeclipse.ini.old
just in case something goes wrong - Rename
eclipse(1).ini
toeclipse.ini
Open your newly-renamed
eclipse.ini
and 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
- 找到您的
eclipse.ini
文件并将其复制粘贴到同一目录中(应命名为eclipse(1).ini
) - 重命名
eclipse.ini
为eclipse.ini.old
以防万一出现问题 - 重命名
eclipse(1).ini
为eclipse.ini
打开您新重命名的
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
XXMaxPermSize
may be deprecated, so it might not work. If eclipse still does not launch, do the following:
XXMaxPermSize
可能会被弃用,所以它可能不起作用。如果 eclipse 仍然没有启动,请执行以下操作:
- Delete the newer
eclipse.ini
- Rename
eclipse.ini.old
toeclipse.ini
- Open command prompt
- type in
eclipse -vm C:\Program Files (x86)\Java\jdk1.8.0_60\bin\javaw.exe
- 删除较新的
eclipse.ini
- 重命名
eclipse.ini.old
为eclipse.ini
- 打开命令提示符
- 输入
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.ini
with 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。我做了以下事情:
Modified my eclipse.ini file and added the following after open:
-vm d:\java\jdk1.8.0_161\bin
While creating the java program I have to unselect default build path and then select d:\java.
修改了我的 eclipse.ini 文件,打开后添加了以下内容:
-vm d:\java\jdk1.8.0_161\bin
在创建 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->我的电脑->属性->高级系统设置->环境变量
- 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
- 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
- 如果没有变量 JAVA_HOME,添加变量值为变量,路由到安装 JDK 的文件夹,例如 C:\Program Files\Java\jdk-11.0.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 位)