简体   繁体   English

为Eclipse设置正确的PATH

[英]Setting the correct PATH for Eclipse

I recently changed my path so I could follow along in the Head First Java book and I had Eclipse before. 我最近改变了自己的路径,所以我可以在Head First Java书中继续学习,之前我有过Eclipse。 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. 现在,当我再次尝试进入Eclipse时,它将无法打开,因为它说它无法在我的目录中找到要使用的JRE或JDK。 I have moved the JDK file around. 我已经移动了JDK文件。 I have jdk1.8.0_60 downloaded. 我已经下载了jdk1.8.0_60。 So how can I get Eclipse to open again? 那么我怎样才能让Eclipse再次打开?

Like Abob said : 像阿布说

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 . 您应该在eclipse.ini文件中指定Eclipse应该在哪里找到您的JDK。 Specifically, the following parameter (note that it is 2 separate lines in the ini file): 具体来说,以下参数(注意它在ini文件中是2个单独的行):

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

or wherever your javaw.exe happens to be. 或者你的javaw.exe恰好在哪里。

Note: The format of the ini file is very particular; 注意: ini文件的格式非常特殊; make sure to consult https://wiki.eclipse.org/Eclipse.ini to ensure you get it exactly right. 请务必查阅https://wiki.eclipse.org/Eclipse.ini以确保您完全正确。

Eclipse folder has an initialization file which is used by eclipse on launch/Double click it is named as eclipse.ini. Eclipse文件夹有一个初始化文件,eclipse在启动时使用/双击它命名为eclipse.ini。 Add the following lines in eclipse.ini file. 在eclipse.ini文件中添加以下行。 Where the vm defines the path of J VM with which we want eclipse to use. 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

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. 尽管Eclipse没有参考JAVA_HOME变量,但设置它仍然是个好主意。 See How do I run Eclipse? 请参阅如何运行Eclipse? for more information. 欲获得更多信息。

If you have not created and/or do not see JAVA_HOME under the list of System variables , do the following: 如果您尚未在System variables列表下创建和/或未看到JAVA_HOME ,请执行以下操作:

  1. Click New... at the very bottom 单击最底部的New...
  2. For Variable name , type JAVA_HOME exactly 对于Variable name ,请完全键入JAVA_HOME
  3. For Variable value , this could be different depending on what bits your computer and java are. 对于Variable value ,这可能会有所不同,具体取决于您的计算机和Java的位数。
    • If both your computer and java are 64-bit , type C:\\Program Files\\Java\\jdk1.8.0_60 如果您的计算机和Java都是64位 ,请键入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 如果您的计算机和Java都是32位 ,请键入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 如果您的计算机是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 variables that you see JAVA_HOME in 单击您在JAVA_HOME中看到的System variables下的行
  2. Click Edit... at the very bottom 单击最底部的Edit...
  3. For Variable value , change it to what was stated in #3 above based on java's and your computer's bits. 对于Variable value ,根据java和计算机的位将其更改为上面#3中所述的值。 To repeat: 重复:
    • If both your computer and java are 64-bit , change it to C:\\Program Files\\Java\\jdk1.8.0_60 如果您的计算机和Java都是64位 ,请将其更改为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 如果您的计算机和Java都是32位 ,请将其更改为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 如果您的计算机是64位 ,但您的java是32位 ,请将其更改为C:\\Program Files (x86)\\Java\\jdk1.8.0_60

Next, add to your PATH variable 接下来,添加到PATH变量

  1. Click on the row under System variables with PATH in it 单击System variables下的行,其中包含PATH
  2. Click Edit... at the very bottom 单击最底部的Edit...
  3. If you have a newer version of windows: 如果您有更新版本的Windows:
    • Click New 单击New
    • Type in C:\\Program Files (x86)\\Java\\jdk1.8.0_60 OR C:\\Program Files\\Java\\jdk1.8.0_60 depending on the bits of your computer and java (see above ^). 键入C:\\Program Files (x86)\\Java\\jdk1.8.0_60 C:\\Program Files\\Java\\jdk1.8.0_60具体取决于计算机和java的位(参见上文^)。
    • Press Enter and Click New again. Enter并再次单击“ New
    • Type in C:\\Program Files (x86)\\Java\\jdk1.8.0_60\\jre OR C:\\Program Files\\Java\\jdk1.8.0_60\\jre depending on the bits of your computer and java (see above again ^). 键入C:\\Program Files (x86)\\Java\\jdk1.8.0_60\\jre OR C:\\Program Files\\Java\\jdk1.8.0_60\\jre具体取决于计算机和java的位(请参见上文^)。
    • Press Enter and press OK on all of the related windows Enter并在所有相关窗口上按OK
  4. If you have an older version of windows 如果您有旧版本的Windows
    • In the Variable value textbox (or something similar) drag the cursor all the way to the very end 在“ Variable value文本框(或类似的东西)中,将光标一直拖到最后
    • Add a semicolon ( ; ) if there isn't one already 如果没有分号;则添加分号( ;
    • C:\\Program Files (x86)\\Java\\jdk1.8.0_60 OR C:\\Program Files\\Java\\jdk1.8.0_60 C:\\Program Files (x86)\\Java\\jdk1.8.0_60 C:\\Program Files\\Java\\jdk1.8.0_60
    • Add another semicolon ( ; ) 添加另一个分号( ;
    • C:\\Program Files (x86)\\Java\\jdk1.8.0_60\\jre OR C:\\Program Files\\Java\\jdk1.8.0_60\\jre C:\\Program Files (x86)\\Java\\jdk1.8.0_60\\jre OR C:\\Program Files\\Java\\jdk1.8.0_60\\jre

Changing eclipse.ini 改变eclipse.ini

  1. Find your eclipse.ini file and copy-paste it in the same directory (should be named eclipse(1).ini ) 找到你的eclipse.ini文件并将其复制粘贴到同一目录中(应该命名为eclipse(1).ini
  2. Rename eclipse.ini to eclipse.ini.old just in case something goes wrong eclipse.ini重命名为eclipse.ini.old以防万一出错
  3. Rename eclipse(1).ini to eclipse.ini eclipse(1).ini重命名为eclipse.ini
  4. Open your newly-renamed eclipse.ini and replace all of it with this: 打开新重命名的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. XXMaxPermSize可能已被弃用,因此可能无效。 If eclipse still does not launch, do the following: 如果eclipse仍未启动,请执行以下操作:

  1. Delete the newer eclipse.ini 删除较新的eclipse.ini
  2. Rename eclipse.ini.old to eclipse.ini eclipse.ini.old重命名为eclipse.ini
  3. Open command prompt 打开命令提示符
  4. type in eclipse -vm C:\\Program Files (x86)\\Java\\jdk1.8.0_60\\bin\\javaw.exe eclipse -vm C:\\Program Files (x86)\\Java\\jdk1.8.0_60\\bin\\javaw.exe键入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. 尝试将您的eclipse和java更新到最新版本。 8u60 ( 1.8.0_60 ) is not the latest version of java. 8u60( 1.8.0_60 )不是java的最新版本。 Sometimes, the latest version of java doesn't work with older versions of eclipse and vice versa. 有时,最新版本的java不适用于旧版本的eclipse,反之亦然。 Otherwise, leave a comment if you're still having problems. 否则,如果您仍然遇到问题,请发表评论。 You could also try a fresh reinstallation of Java. 您也可以尝试重新安装Java。

I am using Windows 8.1 environment. 我正在使用Windows 8.1环境。 I had the same problem while running my first java program after installing Eclipse recently. 我最近在安装Eclipse后运行第一个java程序时遇到了同样的问题。 I had installed java on d drive at d:\\java. 我在d:\\ java上的d驱动器上安装了java。 But Eclipse was looking at the default installation c:\\programfiles\\java. 但Eclipse正在查看默认安装c:\\ programfiles \\ java。 I did the following: 我做了以下事情:

  1. Modified my eclipse.ini file and added the following after open: 修改了我的eclipse.ini文件并在打开后添加了以下内容:

     -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. 在创建java程序时,我必须取消选择默认构建路径,然后选择d:\\ java。

After this, the program ran well and got the hello world to work. 在此之后,该程序运行良好,让hello world工作。

There are working combinations of OS, JDK and Eclipse bitness. OS,JDK和Eclipse bitness有工作组合。 In my case, I was using a 64-bit JDK with a 32-bit Eclipse on a 64-bit OS. 就我而言,我在64位操作系统上使用64位JDK和32位Eclipse。 After downgrading the JDK to 32-bit, Eclipse started working. 在将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位)

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.ini进行了比较,并开始删除选项并测试eclipse是否有效。

The only option that prevented eclipse from starting was -XX:+UseParallelGC , so I removed it and voilá! 阻止eclipse启动的唯一选择是-XX:+UseParallelGC ,所以我删除了它并且瞧!

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 如果没有变量JAVA_HOME,请将其添加为变量值,并将路径添加到安装JDK的文件夹中,例如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 如果没有变量PATH或它有另一个值,请将变量值更改为C:\\ Program Files \\ Java \\ jdk-11.0.2 \\ bin或使用此值添加变量PATH

Good Luck 祝好运

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

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