问题
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?
回答1:
Like Abob said:
Eclipse doesn't consult the
JAVA_HOMEvariable
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):
-vm
C:\Java\JDK\1.8\bin\javaw.exe
or wherever your javaw.exe happens to be.
Note: The format of the ini file is very particular; make sure to consult https://wiki.eclipse.org/Eclipse.ini to ensure you get it exactly right.
回答2:
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 JVM with which we want eclipse to use.
-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
回答3:
Go to System Properties > Advanced > Enviroment Variables and look under System variables
First, create/set your JAVA_HOME variable
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.
If you have not created and/or do not see JAVA_HOME under the list of System variables, do the following:
- Click
New...at the very bottom - For
Variable name, typeJAVA_HOMEexactly - 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
If you have created and/or do see JAVA_HOME, do the following:
- Click on the row under
System variablesthat you seeJAVA_HOMEin - 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
Next, add to your PATH variable
- Click on the row under
System variableswithPATHin it - Click
Edit...at the very bottom - If you have a newer version of 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 ClickNewagain. - 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 pressOKon all of the related windows
- Click
- If you have an older version of 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
- In the
Changing eclipse.ini
- Find your
eclipse.inifile and copy-paste it in the same directory (should be namedeclipse(1).ini) - Rename
eclipse.initoeclipse.ini.oldjust in case something goes wrong - Rename
eclipse(1).initoeclipse.ini 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
XXMaxPermSize may be deprecated, so it might not work. If eclipse still does not launch, do the following:
- Delete the newer
eclipse.ini - Rename
eclipse.ini.oldtoeclipse.ini - Open command prompt
- type in
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.
回答4:
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:
Modified my eclipse.ini file and added the following after open:
-vm d:\java\jdk1.8.0_161\binWhile creating the java program I have to unselect default build path and then select d:\java.
After this, the program ran well and got the hello world to work.
回答5:
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.
Kindly use one of the following combinations.
32-bit OS, 32-bit JDK, 32-bit Eclipse (32-bit only)
64-bit OS, 32-bit JDK, 32-bit Eclipse
64-bit OS, 64-bit JDK, 64-bit Eclipse (64-bit only)
回答6:
For me none worked. I compared my existing eclipse.ini with a new one and started removing options and testing if eclipse worked.
The only option that prevented eclipse from starting was -XX:+UseParallelGC, so I removed it and voilá!
回答7:
I have resolved this problem by adding or changing variables in environment variables. Go to Win7 -> My Computer - > Properties - > Advanced system settings -> environment Variables
- 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
Good Luck
来源:https://stackoverflow.com/questions/35881210/setting-the-correct-path-for-eclipse