How to detect where java is installed

Hi guysI need to write a java program that detects where J2SE or J2EE is installed?Any suggestions... thank you
[159 byte] By [Brannos] at [2007-9-30 11:10:51]
# 1

You could check the environment variables for JAVA_HOME, J2EE_HOME, etc.

In windows, you can look in the registry:

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoct\Java Runtime Environment\1.4\JavaHome

Replacing, of course, 1.4 with the version you're looking for (1.4.2_04 for example)

If you're RUNNING java already - use the System.properties

see http://java.sun.com/docs/books/tutorial/essential/system/properties.html

You want the property "java.home"

+Michael

michaelriecken at 2007-7-3 23:00:35 > top of Java-index,Administration Tools,Sun Connection...
# 2
Of course you notice these things AFTER you post - the registry path is\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4\JavaHomeand not JavaSoct as previously posted.+M
michaelriecken at 2007-7-3 23:00:35 > top of Java-index,Administration Tools,Sun Connection...
# 3
Thank you for the reply..What I need to detect is all places where java might be installed in. You know like a machine can have different versions of java or J2EE or J2ME.. So I wonder if there is a way of telling all the places where java is installed
Brannos at 2007-7-3 23:00:35 > top of Java-index,Administration Tools,Sun Connection...
# 4

If it's a windows machine, you can look in the registry.

Each version will have its own branch in the registry tree.

Mine looks like this

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.4

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.4.2_04

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.5

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.5.0

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Plug-in\1.4.2_04

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4.2_04

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.01

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1_02

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1_03

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1_04

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.2

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.2.0_01

\\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.4.2_04

Each branch has a key named "Home" and a value that is the install directory.

michaelriecken at 2007-7-3 23:00:35 > top of Java-index,Administration Tools,Sun Connection...
# 5
Or on unix, use locate ('locate java') - assuming slocate has been updated
EvilEdna at 2007-7-3 23:00:35 > top of Java-index,Administration Tools,Sun Connection...
# 6
if in windows base, do this easy way, run command prompt, and then enter command " cd\ " ( enter )and then enter other command " dir/s javac.exe " (enter ) wait for a min, you will see where the javac.exe save. hehe :) good luck, i am new on java too.
luckybar at 2007-7-3 23:00:35 > top of Java-index,Administration Tools,Sun Connection...
# 7
I would use System.getProperty("java.home");On my machine, it gives the directory of the JRE.
atmguy at 2007-7-3 23:00:35 > top of Java-index,Administration Tools,Sun Connection...