Monday, August 31, 2009

Eclipse.ini / Windows Vista - Don't hardcode Vm; Use JAVA_HOME

I have a little trick for those of you using Windows Vista (and possibly XP), running Eclipse and fed up of editing your eclipse.ini file each and every time you upgrade your JAVA installation! You know what I mean!

According to Eclipsepedia, you need to tell Eclipse the exact path to your JAVA executable. You cannot use JAVA_HOME or any other variable name in this file!

Here we are going to show you how to make Eclipse use your JAVA_HOME directory so that when new versions (one of the umpteen updates) of JAVA are installed, Eclipse just works!

Assumptions:
  • You are using Windows Vista (or possible XP).
  • You know the exact path to your Eclipse installation directory.
  • You know the exact path of the JVM that your eclipse installation is utilizing.
  • The variable JAVA_HOME is set up on your computer.
To begin, navigate to the folder, using an elevated command prompt, that contains your Eclipse installation. For example, on my machine, that folder is C:\eclipse.

The next step is to enter the following command at the prompt:

mklink /D java %JAVA_HOME%

Basically, we are telling Windows to create a symbolic link from the eclipse home directory, to the JAVA_HOME directory and to call this link java. Windows uses a program called mklink to do this.The output from that command will should resemble something like:


For those of you curious to see what happens when I list the directory contents:


The final step is now to put our symbolic link in the eclipse.ini file. So open up the eclipse.ini file (you can create a backup first if you like) and look for the lines that look like:
-vm
C:\path\to\JAVA_SDK\bin\javaw.exe

and replace them with:
-vm
java\bin\javaw.exe

Remember, that you are editing 2 lines (the -vm is on one line, while the java\bin\javaw.exe is on another)!
To confirm that everything works as promised, save your eclipse.ini file and start up eclipse!

2 comments:

vadimv82 said...

If u have spaces in your java_home url, it won't work.

You need to add "" around %JAVA_HOME%. Tested on Windows 7.

mklink /D java "%JAVA_HOME%"

And need to run cmd as admin, otherwise you get "insufficient privileges"

vadimv82 said...

One more thing. I am using Springsource Tool Suite.
And placing -vm argument to the end of eclipse.ini (sts.ini in my case) won't work. I also found that it should be at the beginning of the .ini file.