I'm hoping someone here can point me in the right direction. What
is the most reliable way to detect the available JREs installed on a
target system? Is the Windows registry sufficient under Windows?
Where does one look on a Linux system?
Any help on this matter would be greatly appreciated.
Thanks!
Damon Courtney
SMC - 07 Apr 2005 02:40 GMT
> I'm hoping someone here can point me in the right direction. What
> is the most reliable way to detect the available JREs installed on a
> target system? Is the Windows registry sufficient under Windows? Where
> does one look on a Linux system?
Complex thing to do. Do you want all installed versions?
In Linux, if you just want the current version, the JAVA_HOME environment
variable may give you some clues. Otherwise executing java -version will
tell you the active version (if there is any to run).
This snippet from the Tomcat startup script may also give you some ideas:
### JVM lookup
if [ -z "$JAVA_HOME" ]; then
# Search for java in PATH
JAVA=`which java`
if [ -n "$JAVA" ] ; then
JAVA_BINDIR=`dirname ${JAVA}`
JAVA_HOME="${JAVA_BINDIR}/.."
fi
# Default clean JAVA_HOME
[ -z "$JAVA_HOME" -a -d "/usr/lib/java" ] && JAVA_HOME="/usr/lib/java"
# Default IBM JAVA_HOME
[ -z "$JAVA_HOME" -a -d "/opt/IBMJava2-13" ] && JAVA_HOME="/opt/IBMJava2-13"
[ -z "$JAVA_HOME" -a -d "/opt/IBMJava2-131" ] && JAVA_HOME="/opt/IBMJava2-131"
[ -z "$JAVA_HOME" -a -d "/opt/IBMJava2-14" ] && JAVA_HOME="/opt/IBMJava2-14"
[ -z "$JAVA_HOME" -a -d "/opt/IBMJava2-141" ] && JAVA_HOME="/opt/IBMJava2-141"
# Another solution
[ -z "$JAVA_HOME" -a -d "/usr/java/jdk" ] && JAVA_HOME="/usr/java/jdk"
# madeinlinux JAVA_HOME
[ -z "$JAVA_HOME" -a -d "/usr/local/jdk1.2.2" ] && JAVA_HOME="/usr/local/jdk1.2.2"
# Kondara JAVA_HOME
[ -z "$JAVA_HOME" -a -d "/usr/lib/java/jdk1.2.2" ] && JAVA_HOME="/usr/lib/java/jdk1.2.2"
# Other commonly found JAVA_HOMEs
[ -z "$JAVA_HOME" -a -d "/usr/jdk1.2" ] && JAVA_HOME="/usr/jdk1.2"
# Default Caldera JAVA_HOME
[ -z "$JAVA_HOME" -a -d "/opt/java-1.3" ] && JAVA_HOME="/opt/java-1.3"
# Add other locations here
if [ -z "$JAVA_HOME" ]; then
echo "No JAVA_HOME specified in ${TOMCAT_CFG} and no java found, exiting..." exit 1
else
echo "Found JAVA_HOME: ${JAVA_HOME}"
echo "Please complete your ${TOMCAT_CFG} so we won't have to look for it next time"
fi
fi
No idea about Windoze.
HTH

Signature
Sean
Work expands to occupy the time available - Parkinson's 1st law
"." - 07 Apr 2005 15:28 GMT
> I'm hoping someone here can point me in the right direction. What
> is the most reliable way to detect the available JREs installed on a
> target system? Is the Windows registry sufficient under Windows?
> Where does one look on a Linux system?
>
> Any help on this matter would be greatly appreciated.
As far as I'm aware there is no standard way to detect all available JREs
on a system. Even if you stick to Windows it is not possible. I have a set
of JREs on a network machine. I can map any or all of them to my local
machine. There is nothing in my registry to let you know they exist.
Bottom line, you have to search the system for signs of the JRE. How you
do that will depend on the OS. You could search for the file rt.jar,
knowing that rt.jar is going to be in %JRE_HOME%\lib\.
On UNIX you could use:
find / -name rt.jar -print > results.txt
This will place the results in the text file results.txt. You might also
want to redirect stderr to /dev/null since there will be a number of
directories you don't have permission to enter.
On Windows I right click on My Computer and select Search... or I use a
bash shell for Windows and the UNIX find command. For MSDOS you could try
something like:
dir \rt.jar /s/b > results.txt
How long this takes depends on how big your system is. The more data on
the hard drives the long it will take.

Signature
Send e-mail to: darrell dot grainger at utoronto dot ca