Difference between revisions of "Windows registry vs. Java JDK/JRE installation"

From CodeCodex

(Java)
 
(Implementations)
 
Line 6: Line 6:
 
Finally, the JRE will only use the registry if it is run from the Windows system directory (ex . C:/winnt/system32/java.exe). This would happen if the user just types "java" on the commandline in some random directory, because the system directory is always in the user's path. In this situation, the java.exe will locate the current Java installation by looking at the registry key  
 
Finally, the JRE will only use the registry if it is run from the Windows system directory (ex . C:/winnt/system32/java.exe). This would happen if the user just types "java" on the commandline in some random directory, because the system directory is always in the user's path. In this situation, the java.exe will locate the current Java installation by looking at the registry key  
  
<highlightsyntax language="java122">
+
<pre class="java">
 
[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion]
 
[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion]
  
  
</highlightsyntax>
+
</pre>
 
and then get the path of the JRE from the corresponding key  
 
and then get the path of the JRE from the corresponding key  
<highlightsyntax language="java122">
+
<pre class="java">
 
[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5\JavaHome]
 
[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5\JavaHome]
 
+
</pre>
 
+
</highlightsyntax>
+
 
Beware that some software (eg. Oracle) installs themself at the beginning of the PATH definition, so it's their Java installation that will be found first.  
 
Beware that some software (eg. Oracle) installs themself at the beginning of the PATH definition, so it's their Java installation that will be found first.  
 
You can run the absolute path to the java.exe file, as in  
 
You can run the absolute path to the java.exe file, as in  
  
<highlightsyntax language="java122">
+
<pre class="java">
 
"C:\Program Files\Java\jre1.5.0\bin\java.exe" MyClass   
 
"C:\Program Files\Java\jre1.5.0\bin\java.exe" MyClass   
</highlightsyntax>
+
</pre>
 
It will not use the registry, and it will be guaranteed to use jre1.5.0.  
 
It will not use the registry, and it will be guaranteed to use jre1.5.0.  
 
So for a regular Java SE program, it is safe to specify the complete path to the JRE to launch it.  
 
So for a regular Java SE program, it is safe to specify the complete path to the JRE to launch it.  
  
 
But for the Applet/Plugin or WebStart-based programs, the registry is always used to determine the current JRE.  
 
But for the Applet/Plugin or WebStart-based programs, the registry is always used to determine the current JRE.  
 +
 +
=== Tcl ===
 +
<pre class="tcl">
 +
package require registry
 +
registry get "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime\\Environment\\1.5\\JavaHome" "Path"
 +
registry get "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"  "ProductName"
 +
</pre>
 
[[Category:Java]]
 
[[Category:Java]]
 +
[[Category:Tcl]]

Latest revision as of 14:52, 20 February 2011

Implementations[edit]

Java[edit]

The JDK itself does not use the windows registry to run. It is the JRE that uses the system registry to run in some situations like an Applet or a program started with the WebStart technolgy.

Finally, the JRE will only use the registry if it is run from the Windows system directory (ex . C:/winnt/system32/java.exe). This would happen if the user just types "java" on the commandline in some random directory, because the system directory is always in the user's path. In this situation, the java.exe will locate the current Java installation by looking at the registry key

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion]


and then get the path of the JRE from the corresponding key

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.5\JavaHome]

Beware that some software (eg. Oracle) installs themself at the beginning of the PATH definition, so it's their Java installation that will be found first. You can run the absolute path to the java.exe file, as in

"C:\Program Files\Java\jre1.5.0\bin\java.exe" MyClass  

It will not use the registry, and it will be guaranteed to use jre1.5.0. So for a regular Java SE program, it is safe to specify the complete path to the JRE to launch it.

But for the Applet/Plugin or WebStart-based programs, the registry is always used to determine the current JRE.

Tcl[edit]

package require registry
registry get "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime\\Environment\\1.5\\JavaHome" "Path"
registry get "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"  "ProductName"