Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | # contributor license agreements. See the NOTICE file distributed with |
| 5 | # this work for additional information regarding copyright ownership. |
| 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | # (the "License"); you may not use this file except in compliance with |
| 8 | # the License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
| 18 | # ----------------------------------------------------------------------------- |
| 19 | # Set CLASSPATH and Java options |
| 20 | # ----------------------------------------------------------------------------- |
| 21 | |
| 22 | # Make sure prerequisite environment variables are set |
| 23 | if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then |
| 24 | if $darwin; then |
| 25 | # Bugzilla 54390 |
| 26 | if [ -x '/usr/libexec/java_home' ] ; then |
| 27 | export JAVA_HOME=`/usr/libexec/java_home` |
| 28 | # Bugzilla 37284 (reviewed). |
| 29 | elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then |
| 30 | export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" |
| 31 | fi |
| 32 | else |
| 33 | JAVA_PATH=`which java 2>/dev/null` |
| 34 | if [ "x$JAVA_PATH" != "x" ]; then |
| 35 | JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null` |
| 36 | JRE_HOME=`dirname $JAVA_PATH 2>/dev/null` |
| 37 | fi |
| 38 | if [ "x$JRE_HOME" = "x" ]; then |
| 39 | # XXX: Should we try other locations? |
| 40 | if [ -x /usr/bin/java ]; then |
| 41 | JRE_HOME=/usr |
| 42 | fi |
| 43 | fi |
| 44 | fi |
| 45 | if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then |
| 46 | echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined" |
| 47 | echo "At least one of these environment variable is needed to run this program" |
| 48 | exit 1 |
| 49 | fi |
| 50 | fi |
| 51 | if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then |
| 52 | echo "JAVA_HOME should point to a JDK in order to run in debug mode." |
| 53 | exit 1 |
| 54 | fi |
| 55 | if [ -z "$JRE_HOME" ]; then |
| 56 | JRE_HOME="$JAVA_HOME" |
| 57 | fi |
| 58 | |
| 59 | # If we're running under jdb, we need a full jdk. |
| 60 | if [ "$1" = "debug" ] ; then |
| 61 | if [ "$os400" = "true" ]; then |
| 62 | if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then |
| 63 | echo "The JAVA_HOME environment variable is not defined correctly" |
| 64 | echo "This environment variable is needed to run this program" |
| 65 | echo "NB: JAVA_HOME should point to a JDK not a JRE" |
| 66 | exit 1 |
| 67 | fi |
| 68 | else |
| 69 | if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then |
| 70 | echo "The JAVA_HOME environment variable is not defined correctly" |
| 71 | echo "This environment variable is needed to run this program" |
| 72 | echo "NB: JAVA_HOME should point to a JDK not a JRE" |
| 73 | exit 1 |
| 74 | fi |
| 75 | fi |
| 76 | fi |
| 77 | if [ -z "$BASEDIR" ]; then |
| 78 | echo "The BASEDIR environment variable is not defined" |
| 79 | echo "This environment variable is needed to run this program" |
| 80 | exit 1 |
| 81 | fi |
| 82 | if [ ! -x "$BASEDIR"/bin/setclasspath.sh ]; then |
| 83 | if $os400; then |
| 84 | # -x will Only work on the os400 if the files are: |
| 85 | # 1. owned by the user |
| 86 | # 2. owned by the PRIMARY group of the user |
| 87 | # this will not work if the user belongs in secondary groups |
| 88 | eval |
| 89 | else |
| 90 | echo "The BASEDIR environment variable is not defined correctly" |
| 91 | echo "This environment variable is needed to run this program" |
| 92 | exit 1 |
| 93 | fi |
| 94 | fi |
| 95 | |
| 96 | # Don't override the endorsed dir if the user has set it previously |
| 97 | if [ -z "$JAVA_ENDORSED_DIRS" ]; then |
| 98 | # Set the default -Djava.endorsed.dirs argument |
| 99 | JAVA_ENDORSED_DIRS="$BASEDIR"/endorsed |
| 100 | fi |
| 101 | |
| 102 | # OSX hack to CLASSPATH |
| 103 | JIKESPATH= |
| 104 | if [ `uname -s` = "Darwin" ]; then |
| 105 | OSXHACK="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes" |
| 106 | if [ -d "$OSXHACK" ]; then |
| 107 | for i in "$OSXHACK"/*.jar; do |
| 108 | JIKESPATH="$JIKESPATH":"$i" |
| 109 | done |
| 110 | fi |
| 111 | fi |
| 112 | |
| 113 | # Set standard commands for invoking Java. |
| 114 | _RUNJAVA="$JRE_HOME"/bin/java |
| 115 | if [ "$os400" != "true" ]; then |
| 116 | _RUNJDB="$JAVA_HOME"/bin/jdb |
| 117 | fi |