3 # Author: Chris Koeritz
5 # this script tries to intuit where java is installed on this machine.
7 ############################
12 which which &>/dev/null
14 # there is no which command here. we produce nothing due to this.
17 echo $(which $to_find)
20 # this reports when we have totally failed to figure out where a folder
21 # is actually located on the machine.
22 function intuition_failure()
25 if [ ! -z "$SHELL_DEBUG" ]; then
26 echo "Could not intuit '$missing' variable."
28 # remove the variable because its value is busted.
32 ############################
34 # set some fairly liberal limits for ant.
35 export ANT_OPTS="-Xms512m -Xmx768m -XX:MaxPermSize=768m"
37 ############################
39 # start guessing some settings...
41 # this bin portion works for most javas...
42 export JAVA_BIN_PIECE=bin
44 if [ ! -d "$JAVA_HOME" ]; then
45 # first try a recent linux version.
46 export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
48 if [ ! -d "$JAVA_HOME" ]; then
49 # try an even more recent version.
50 export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
52 if [ ! -d "$JAVA_HOME" ]; then
53 # try using a windows version.
54 #note: this logic is untested.
55 # probably will break due to space in path issues.
56 declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jdk" 2>/dev/null)
57 if [ ${#any_there[*]} -gt 0 ]; then
58 (( last = ${#any_there[@]} - 1 ))
59 JAVA_HOME="${any_there[$last]}"
61 if [ ! -d "$JAVA_HOME" ]; then
62 # if no jdk, try a jre.
63 declare -a any_there=$(find "/c/Program Files/java" -type d -iname "jre" 2>/dev/null)
64 if [ ${#any_there[*]} -gt 0 ]; then
65 (( last = ${#any_there[@]} - 1 ))
66 JAVA_HOME="${any_there[$last]}"
70 # this should go last, since it changes the bin dir.
71 if [ ! -d "$JAVA_HOME" ]; then
72 # if that didn't work, try the location for mac os x.
73 JAVA_HOME=/Library/Java/Home
74 JAVA_BIN_PIECE=Commands
76 # last thing is to tell them we couldn't find it.
77 if [ ! -d "$JAVA_HOME" -a -z "$(whichable java 2>/dev/null)" ]; then
78 intuition_failure JAVA_HOME
82 ############################
84 # intuit where we have our local eclipse.
85 if [ ! -d "$ECLIPSE_DIR" ]; then
86 export ECLIPSE_DIR=/usr/local/eclipse_jee
88 if [ ! -d "$ECLIPSE_DIR" ]; then
89 ECLIPSE_DIR=$HOME/eclipse
91 if [ ! -d "$ECLIPSE_DIR" ]; then
92 ECLIPSE_DIR=$HOME/apps/eclipse
94 if [ ! -d "$ECLIPSE_DIR" ]; then
95 #uhhh, default on winders?
96 ECLIPSE_DIR="/c/Program Files/eclipse"
98 if [ ! -d "$ECLIPSE_DIR" ]; then
99 ECLIPSE_DIR="/c/tools/eclipse"
101 if [ ! -d "$ECLIPSE_DIR" ]; then
102 ECLIPSE_DIR="/d/tools/eclipse"
104 if [ ! -d "$ECLIPSE_DIR" ]; then
105 ECLIPSE_DIR="/e/tools/eclipse"
107 # final option is to whine.
108 if [ ! -d "$ECLIPSE_DIR" -a -z "$(whichable eclipse 2>/dev/null)" ]; then
109 intuition_failure ECLIPSE_DIR
112 ############################
114 # use the variables we just set in our path, and try to make them override
115 # any other paths to different versions.
117 if [ ! -z "$JAVA_HOME" ]; then
118 export PATH=$JAVA_HOME/$JAVA_BIN_PIECE:$PATH
120 if [ ! -z "$ECLIPSE_DIR" ]; then
121 export PATH=$ECLIPSE_DIR:$PATH
124 ############################