How to run Eclipse with different Java version?

EclipseJava

Eclipse Problem Overview


I am using Eclipse for developing BlackBerry Applications. I have JDK/JRE 7 currently on my computer, but that makes the BlackBerry plugins crash. Actually is a known issue and the only thing need to be done is run Eclipse with JDK/JRE 6 instead of 7.

I downloaded and installed version 6. However I am pretty sure Eclipse still uses 7. I had the same problem a year ago and I remembered I had to configure some System Variables and it worked, but I can't really find the solution now.

Any idea on this one? Important! I don't want to compile in version 6, which means I just have to choose the Java version through Eclipse. What I need is Eclipse to start with version 6.

Eclipse Solutions


Solution 1 - Eclipse

  • Open eclipse config file eclipse.ini in your Eclipse folder.

  • Add -vm yourPath\Java\jre6\bin\javaw.exe like:

      -startup
      plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
      --launcher.library
      plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120522-1813
      -product
      org.eclipse.epp.package.java.product
      --launcher.defaultAction
      openFile
      --launcher.XXMaxPermSize
      256M
      -vm 
      C:\Java\jre6\bin\javaw.exe
      ...
    

If the path contains spaces there is no need to escape them, see the Eclipse Wiki for more specs. The -vm option and the path must be on separate lines. The -vm option must come before the -vmargs option. On Linux, the path would typically be /bin/java instead of the Windows path shown above. You must use the Java and Eclipse versions must match (i.e. 32-bit Eclipse runs on 32-bit Java and 64-bit Eclipse runs on 64-bit Java).

Solution 2 - Eclipse

Note that option -vm C:\Java\jre6\bin\javaw.exe should be right before -vmargs. Otherwise you'll get 'Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit'

Solution 3 - Eclipse

Do this:

  1. Go to the folder where eclipse is installed (the one that has the eclipse.exe program in)

  2. Open the text file eclipse.ini with notepad or something similar

  3. Add the following lines to specify the JVM location using the -vm argument

    -vm c:/jre/bin/javaw.exe

Now start eclipse in the usual way.

Make sure to position the -vm argument before -vmargs, since the latter is passed to the VM on startup it will be too late to set the VM after this.

More info is available on the Eclipse wiki

You could also have changed the system path as per one of the other answers but this would change the JVM being used for the whole system. If you use the eclipse.ini settings it allows everything else to use the latest JVM.

Solution 4 - Eclipse

Many hints given already. Anyway I will just provide the recommended way of doing it which might help for future reviews of that question:

  1. Use the eclispe.ini file (folder where the eclipse binary resides)
  2. Add the -vm option with the path of the jre to startup with > i.e Windows
    > -vm
    > C:\Java\jdk1.6.0_45\jre\bin\javaw.exe
    > i.e Linux
    > -vm
    > /opt/sun-jdk-1.6.0.02/bin/java
    >
  3. The -vm option must occur after the other Eclipse-specific options (such as -product, --launcher.*, etc), but before the -vmargs option, since everything after -vmargs is passed directly to the JVM.
  4. The -vm option and its value (the path) must be on separate lines.
  5. The value must be the full absolute or relative path to the Java executable, not just to the Java home directory.

see: the eclipse.ini authoring guidelines from eclipse wiki

Solution 5 - Eclipse

Since none of the answers worked for me this is my solution:

I downloaded java 6 and i installed it. Then in the program files , inside the folder of java , i copied the folder jre6. I pasted it inside the eclipse folder and renamed it jre.

Thats it! When inside the eclipse installation folder your have a folder named jre , then the java in there is the java that eclipse will run with.

Thank you all for your answers!

Solution 6 - Eclipse

These two options worked for me on Windows:

  1. Edit eclipse.ini

    -vm
    
    C:/Java/jdk1.7.0_71/jre/bin
    
    -vmargs
    ...
    
  2. Copy jre folder to eclipse folder.

So after the copy I have C:\eclipse\jre folder which is a copy of C:\Java\jdk1.7.0_71\jre

Solution 7 - Eclipse

I modified eclipse.ini file as follows (added my local JDK path) and it fixed eclipse loading issue.

-vm
C:\Program Files\Java\jdk1.8.0_251\bin 

Solution 8 - Eclipse

If you want to make sure you are running you java apps in Windows 7 with an specific java version:

1 - Check out what which version is running by default. Run cmd to go to the console and type: java -version

> C:>java -version > > java version "1.6.0_45" Java(TM) SE Runtime Environment (build > 1.6.0_45-b06) Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)

2 - Change the default jdk by changing the path. Example here. Make sure you java.exe from your desired jdk is before any other java.exe from any other JDK in the path. ex. in JDK 1.6 you java.exe should be here C:\java\jdk1.6\bin\java.exe.

Once you have changed the path, open a new console and verify again which jdk version you are running.

3 - Make sure in eclipse.ini param -vm another jre version is not set.

Solution 9 - Eclipse

I too faced same issue while running eclipse with different version then default on the system.

I created a symlink of required jre directory under eclipse directory and then it was all working.

For windows user: symlink is similar to creating shortcut

Hope it helps you too.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohny JazView Question on Stackoverflow
Solution 1 - EclipseVan Dan NGUYENView Answer on Stackoverflow
Solution 2 - EclipseBugaBugaView Answer on Stackoverflow
Solution 3 - EclipseBen ThurleyView Answer on Stackoverflow
Solution 4 - EclipsestaiiirView Answer on Stackoverflow
Solution 5 - EclipseJohny JazView Answer on Stackoverflow
Solution 6 - EclipseSabeeshView Answer on Stackoverflow
Solution 7 - Eclipsevani saladhaguView Answer on Stackoverflow
Solution 8 - EclipsePbxManView Answer on Stackoverflow
Solution 9 - EclipseAlok RajputView Answer on Stackoverflow