Setting the correct PATH for Eclipse

222,234

Solution 1

Like Abob said:

Eclipse doesn't consult the JAVA_HOME variable

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.

Solution 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

Solution 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:

  1. Click New... at the very bottom
  2. For Variable name, type JAVA_HOME exactly
  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

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

  1. Click on the row under System variables that you see JAVA_HOME in
  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

Next, add to your PATH variable

  1. Click on the row under System variables with PATH in it
  2. Click Edit... at the very bottom
  3. If you have a newer version of windows:
    • Click 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 ^).
    • Press Enter and Click New again.
    • 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 ^).
    • Press Enter and press OK on all of the related windows
  4. If you have an older version of 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 OR 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

Changing eclipse.ini

  1. Find your eclipse.ini file and copy-paste it in the same directory (should be named eclipse(1).ini)
  2. Rename eclipse.ini to eclipse.ini.old just in case something goes wrong
  3. Rename eclipse(1).ini to eclipse.ini
  4. 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
    

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

  1. Delete the newer eclipse.ini
  2. Rename eclipse.ini.old to eclipse.ini
  3. Open command prompt
  4. 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.

Solution 4

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

  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

Good Luck

Solution 5

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:

  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.

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

Share:
222,234

Related videos on Youtube

TyngeOfTheGinge
Author by

TyngeOfTheGinge

Updated on July 09, 2022

Comments

  • TyngeOfTheGinge
    TyngeOfTheGinge almost 2 years

    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?

    • Majora320
      Majora320 about 8 years
      Try editing the eclipse.ini file (In ~/eclipse/java-mars/eclipse for me; would probably be in C:\Program Files somewhere for windows.) and changing the line after '-vm' to your actual jdk path.
    • Majora320
      Majora320 about 8 years
      Also, change your PATH to include the jdk directory.
    • aelkz
      aelkz about 8 years
      Also check if you have installed the x32 or x64 version of Java and certify the same for eclipse that you have previously downloaded.
    • TyngeOfTheGinge
      TyngeOfTheGinge about 8 years
      I've tried changing my Path to ThisPC\Desktop\eclipse\jdk1.8.0_60\bin and it's not working. I even tried putting the jdk1.8.0_60 file in the eclipse file itself and that's not working either...
    • Arastais
      Arastais about 8 years
      Moving your JDK file or directory will just mess things up even more; it's an installed program and should be placed where it was originally installed. Eclipse doesn't just look at PATH. Also, you shouldn't be changing your PATH, you should be adding to it. You shouldn't also change PATH to the bin folder, just the default installation directory itself.
  • TyngeOfTheGinge
    TyngeOfTheGinge about 8 years
    It's still not working. I re-downloaded eclipse and put it all in the eclipse2 folder on my desktop. I don't know why I am still getting an error when I try to open Eclipse. The error is saying that no virtual machine was located when looking in this location: C:Users\Ty\Desktop\eclipse2\jre\bin\javaw.exe
  • Arastais
    Arastais about 8 years
    If it can't find the JVM in the eclipse directory, try moving it to C:\Program Files (x86)\Java\jdk1.8.0_60\bin or C:\Program Files\Java\jdk1.8.0_60\bin depending on bits (the default directory; See Finding the JVM) and then following the new section i posted in my answer. If that doesn't work, remove all java installations and install the latest version from here
  • Stevoisiak
    Stevoisiak about 7 years
    It's worth noting this can be used to run Eclipse off a USB drive using Java Portable. Simply use a relative path such as \PortableApps\Programs\CommonFiles\Java\bin
  • E-Riz
    E-Riz almost 7 years
    All of this stuff about JAVA_HOME and PATH is meaningless to running Eclipse. And the advice about replacing the entire contents of eclipse.ini is VERY BAD advice - different packages of Eclipse and different versions will have different contents in eclipse.ini, so blindly replacing them will likely break things. All that's necessary is to make sure there is a -vm parameter and valid value, as described at wiki.eclipse.org/Eclipse.ini
  • Rob Wilson
    Rob Wilson about 6 years
    The note was very helpful - the line only worked for me once I moved it above the -vmargs
  • rvd
    rvd about 6 years
    For Spring Tool Suite [3.8.3.RELEASE-e4.6.2] " -vm C:\Program Files\Java\jdk1.8.0_74\bin\javaw.exe " add the above lines separately and before the following line " --launcher.defaultAction openFile -vmargs -Dosgi.requiredJavaVersion=1.8 "
  • coretechie
    coretechie over 5 years
    Also make sure that correct java version is mapped. Like win32 has jdk_32 and 64 one has that one. Helpful.
  • madladzen
    madladzen almost 4 years
    I can't find -vm in my eclipse.ini file. just -vmargs. What do I do?
  • Christian W
    Christian W almost 4 years
    @madladzen : You can just add it then. -vmargs supplies arguments, -vm points to the jvm that eclipse should use. Take a look at the linked wiki, it explains everything pretty well