2 # This script attempts to locate the jre directory of the current
3 # Java installation, even when java is not in the path
4 # It works with the following rpm files:
5 # Sun's Java Software Development Kit (Linux/Windows)
6 # Sun's Java Runtime Environment (Linux)
7 # IBM's Java Software Development Kit (linux)
9 # We require an option to specify which directory is desired:
10 # --java: directory with java executable
11 # --javac: directory with javac executable
12 # --jni: directory where JNI code is placed
14 if [ "$1" = "--jni" ]; then
16 elif [ "$1" = "--java" ]; then
18 elif [ "$1" = "--javac" ]; then
21 echo "Usage: tos-locate-jre --java|--javac|--jni" >&2
27 javapath
=`rpm -ql $1 2>/dev/null | grep "bin/$2$"`
31 javapath
=`which $1 2>/dev/null`
32 while [ -n "$javapath" -a -h "$javapath" ]; do
33 javapath
=`readlink -f -q $javapath`
40 # Hopefully this will always work on cygwin with Sun's Java
41 jversion
=`regtool -q get '\\HKLM\\SOFTWARE\\JavaSoft\\Java Development Kit\\CurrentVersion'`
45 jhome
=`regtool -q get '\\HKLM\SOFTWARE\\JavaSoft\\Java Development Kit\\'$jversion'\\JavaHome'`
49 jhome
=`cygpath -u "$jhome"`
53 #Just statically typed in, uses default location of installation for XTools. May need to be fixed
54 jhome
=/System
/Library
/Frameworks
/JavaVM.framework
/Versions
/CurrentJDK
58 # Check gentoo java configuration
59 javapath
=`java-config -c 2>/dev/null`
60 # We check the path first, on the assumption that that's the preferred
62 if [ -z "$javapath" ]; then
63 pathlocate javac ||
{ test -z "$javac" && pathlocate java
; }
65 if [ -z "$javapath" ]; then
66 # We try a bunch of standard names, before resorting to rpm -qa
67 rpmlocate IBMJava2-SDK javac || \
68 rpmlocate IBMJava2-142-ia32-SDK javac || \
69 rpmlocate j2sdk javac || \
70 rpmlocate jdk javac || \
71 { test -z "$javac" && rpmlocate j2re java
; } || \
72 { test -z "$javac" && rpmlocate jre java
; }
74 if [ -z "$javapath" ]; then
75 # lastly, check for a weirdly named IBMJava2
76 if [ `which rpm 2>/dev/null` ]; then
77 name
=`rpm -qa | grep IBMJava2 | head -1`
78 if [ -n "$name" ]; then
84 if [ -z "$javapath" ]; then
87 jbin
=`dirname "$javapath"`
88 jhome
=`dirname "$jbin"`
92 # We check the path first, on the assumption that that's the preferred
94 pathlocate javac ||
{ test -z "$javac" && pathlocate java
; }
95 if [ -n "$javapath" ]; then
96 jbin
=`dirname "$javapath"`
98 if [ -f /usr
/local
/jdk1.4
*/bin
/java
]; then
99 jbin
=/usr
/local
/jdk1.4
*/bin
104 jhome
=`dirname $jbin`
108 # These are correct for Sun and IBM's x86 Java versions
109 if [ "$jni" = "yes" ]; then
115 # Look for a likely JNI directory
116 # Windows, and IBM Java: in jre/bin
117 # Sun Java on Linux: in jre/lib/i386
118 if [ `uname` = "Darwin" ]; then
119 jnilocate
"/Library/java/Extensions"
120 elif "$jhome/bin/java" -version 2>&1 |
grep -q IBM || cygpath
-w / >/dev
/null
2>/dev
/null
; then
121 jnilocate
"$jhome/jre/bin" || jnilocate
"$jhome/bin"
124 jnilocate
"$jhome/jre/lib/$arch" || \
125 jnilocate
"$jhome/jre/lib/i386" || \
126 jnilocate
"$jhome/jre/lib/amd64" || \
127 jnilocate
"$jhome/lib/$arch" || \
128 jnilocate
"$jhome/lib/i386" || \
129 jnilocate
"$jhome/lib/amd64"
131 elif [ "$javac" = "yes" ]; then
132 if [ `uname` = "Darwin" ]; then
133 dir
="$jhome/Commands"
137 elif [ "$java" = "yes" ]; then
138 if [ `uname` = "Darwin" ]; then
139 dir
="$jhome/Commands"
145 # Check that what we found actually exists
146 if [ -d "$dir" ]; then