Eclipse is a java program - just a jar. So it needs to run inside a JRE.
The eclipse.exe is a misnomer - it is not the eclipse program, but a program which starts the eclipse program. It does a few initialization things, then calls the eclipse jar with appropriate arguments (I am only showing the most important -jar argument here):
> java -jar eclipse/plugins/org.eclipse.equinox.launcher_1.0.0.v20070606.jar ..
We are familiar with the above command. We are calling the JRE and giving it a -jar argument, pointing to the actual jar which runs Eclipse.
You could have as well called this command from the command line yourself, instead of running eclipse.exe (the misnomer).
Why is all this so important?
Because the immediate question to ask yourself is which JRE is Eclipse running under?
If you just think of the above command:
> java -jar eclipse/plugins/org.eclipse.equinox.launcher_1.0.0.v20070606.jar ..
we can be sure that the OS will look for the 'java' program in its PATH, and execute the first JRE it finds.
This is problematic.
Why?
Because what if we have multiple installs of JDK on our machine (this is quite common) - JDK5, JDK6 and JDK7?
If we are not absolutely sure what is in our PATH, we cannot be sure what Eclipse is running in. Consequently, when we compile our java source in Eclipse, we do not know for sure if we compiled in JDK5, JDK6 or JDK7!
This can lead to serious compilation issues. Sometimes it will give compilation errors because it can't find the necessary libraries, other times it will compile against an older version of the libraries, etc, etc.
To avoid going down this labyrinth of problems, we have the eclipse.ini file.
Instead of relying on the OS to figure out what JRE to use, we will specify it upfront - so we can be absolutely sure what version of JDK we are using.
Open the eclipse.ini file in a text editor - you will find this file in the top directory of your eclipse installation.
At the very top, add the following two lines:
-vm
C:\Program Files\Java\jdk1.6.0_21\bin\javaw.exe
This tell eclipse which Virtual Machine to use.
Note that we are specifying the javaw.exe, and not java.exe - what is the difference?
java.exe and javaw.exe are the exact same thing, with one tiny difference. When you run java.exe, it opens in a console. On the other hand, javaw.exe does not pop up any console.
This is good when an external program, like eclipse.exe or your browser, is runs JRE - so you do not see annoying console windows popping up.
No comments:
Post a Comment