How NativeJ searches for a suitable JDK/JRE

When a NativeJ-generated executable starts up, the first thing it needs to do is to look for a suitable jvm.dll file to run the Java application.

If the JVM DLL parameter is specified, that will be the first place it looks. For example, if the JVM DLL parameter is jre\bin\client\jvm.dll, and the program directory is C:\Program Files\Tomcat, the executable will check if the file C:\Program Files\Tomcat\jre\bin\client\jvm.dll exists. If it does, then the Java application will be started using that file, no questions asked.

Next, the executable will look for a suitable JRE in the Windows registry at HKLM\Software\JavaSoft\Java Runtime Environment. The CurrentVersion value gives the location of the current JRE installed. For example, if the value is "1.4", the details for the current JRE will be available in HKLM\Software\JavaSoft\Java Runtime Environment\1.4\RuntimeLib.

If that fails (file not found, or version mismatch), the executable will iterate through all subkeys under HKLM\Software\JavaSoft\Java Runtime Environment to locate a suitable JRE. The same process is repeated for HKLM\Software\IBM\Java Runtime Environment to locate a JRE from IBM.

If none of the JREs are suitable, the executable will make an attempt to use any JDK installed on the system. It does so by first looking at the CurrentVersion value in HKLM\Software\JavaSoft\Java Developer Kit. Then it looks at the JavaHome value for the current JDK and try various locations for jvm.dll:

If that fails, it iterates through all the subkeys in HKLM\Software\JavaSoft\Java Developer Kit, and check each installed JDK. The same process is repeated for HKLM\Software\IBM\Java Developer Kit to locate a JDK from IBM.

Finally, it checks if the JAVA_HOME environment variable is set. If so, it appends \jre\bin\client\jvm.dll and tries to use that. For example, if JAVA_HOME contains the value c:\Program Files\Java\jdk1.5.0_01, then it will try to load c:\Program Files\Java\jdk1.5.0_01\jre\bin\client\jvm.dll.

If a suitable jvm.dll cannot be located after this comprehensive search process. the executable gives up and displays an error message.