Finding a VM, Using JNI Invocation or Executing Java
It turns out that writing a JNI launcher for multiple vms on multiple platforms is easier said than done. JNI launching does not currently work on all platforms for all vms. Because of this, the launcher can start the Java Virtual Machine either in process through the JNI Invocation API, or in a seperate process by executing the java launcher. Which method is used depends on how the vm was found.
On most platforms, we use JNI launching unless a -vm argument was given that points directly to a java executable.
More specifically, a virtual machine and launch method is chosen as follows:
No -vm specified
When no -vm is specified, the launcher looks for a virtual machine first in a jre directory in the root of eclipse and then on the search path. If java is found in either location, then we look for a jvm shared library (jvm.dll on window, libjvm.so on *nix platforms) relative to that java executable.
If a jvm shared library is found we load it and use the JNI invocation api to start the vm.
If no jvm shared library is found, we exec the java launcher to start the vm in a new process.
-vm specified on command line or in eclipse.ini
Eclipse can be started with "-vm <location>" to indicate a virtual machine to use. There are several possibilities for the value of <location>:
java.exe/javaw.exe: <location> is a path to a java launcher. We exec that java launcher to start the vm in a new process.
jvm.dll or libjvm.so: <location> is a path to a jvm shared library. We attempt to load that library and use the JNI Invocation API to start the vm in the current process.
vmDesc.ee: <location> is a path to a file ending in ".ee". This file is expected to describe the execution environment for a jvm. See the Execution Environment Descriptions page.
directory: <location> is a directory. We look in that directory for: (1) a default.ee file, (2) a java launcher or (3) the jvm shared library. If we find the jvm shared library, we use JNI invocation. If we find a launcher, we attempt to find a jvm library in known locations relative to the launcher. If we find one, we use JNI invocation. If no jvm library is found, we exec java in a new process.