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 -q $javapath`
40 # Hopefully this will always work on cygwin with Sun's Java
41 jversion
=`regtool -q -w 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 name
=`rpm -qa | grep IBMJava2 | head -1`
77 if [ -n "$name" ]; then
82 if [ -z "$javapath" ]; then
85 jbin
=`dirname "$javapath"`
86 jhome
=`dirname "$jbin"`
90 # We check the path first, on the assumption that that's the preferred
92 pathlocate javac ||
{ test -z "$javac" && pathlocate java
; }
93 if [ -n "$javapath" ]; then
94 jbin
=`dirname "$javapath"`
96 if [ -f /usr
/local
/jdk1.4
*/bin
/java
]; then
97 jbin
=/usr
/local
/jdk1.4
*/bin
102 jhome
=`dirname $jbin`
106 # These are correct for Sun and IBM's x86 Java versions
107 if [ "$jni" = "yes" ]; then
113 # Look for a likely JNI directory
114 # Windows, and IBM Java: in jre/bin
115 # Sun Java on Linux: in jre/lib/i386
116 if [ `uname` = "Darwin" ]; then
117 jnilocate
"/Library/java/Extensions"
118 elif "$jhome/bin/java" -version 2>&1 |
grep -q IBM || cygpath
-w / >/dev
/null
2>/dev
/null
; then
119 jnilocate
"$jhome/jre/bin" || jnilocate
"$jhome/bin"
122 jnilocate
"$jhome/jre/lib/$arch" || \
123 jnilocate
"$jhome/jre/lib/i386" || \
124 jnilocate
"$jhome/jre/lib/amd64" || \
125 jnilocate
"$jhome/lib/$arch" || \
126 jnilocate
"$jhome/lib/i386" || \
127 jnilocate
"$jhome/lib/amd64"
129 elif [ "$javac" = "yes" ]; then
130 if [ `uname` = "Darwin" ]; then
131 dir
="$jhome/Commands"
135 elif [ "$java" = "yes" ]; then
136 if [ `uname` = "Darwin" ]; then
137 dir
="$jhome/Commands"
143 # Check that what we found actually exists
144 if [ -d "$dir" ]; then