Cheng Tang | 697ce24 | 2014-04-27 16:18:17 +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 JAVA_HOME or JRE_HOME if not already set, ensure any provided settings |
| 20 | # are valid and consistent with the selected start-up options and set up the |
| 21 | # endorsed directory. |
| 22 | # |
| 23 | # $Id: setclasspath.sh 1430568 2013-01-08 22:08:57Z schultz $ |
| 24 | # ----------------------------------------------------------------------------- |
| 25 | |
| 26 | # Make sure prerequisite environment variables are set |
| 27 | if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then |
| 28 | if $darwin; then |
| 29 | # Bugzilla 54390 |
| 30 | if [ -x '/usr/libexec/java_home' ] ; then |
| 31 | export JAVA_HOME=`/usr/libexec/java_home` |
| 32 | # Bugzilla 37284 (reviewed). |
| 33 | elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then |
| 34 | export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" |
| 35 | fi |
| 36 | else |
| 37 | JAVA_PATH=`which java 2>/dev/null` |
| 38 | if [ "x$JAVA_PATH" != "x" ]; then |
| 39 | JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null` |
| 40 | JRE_HOME=`dirname $JAVA_PATH 2>/dev/null` |
| 41 | fi |
| 42 | if [ "x$JRE_HOME" = "x" ]; then |
| 43 | # XXX: Should we try other locations? |
| 44 | if [ -x /usr/bin/java ]; then |
| 45 | JRE_HOME=/usr |
| 46 | fi |
| 47 | fi |
| 48 | fi |
| 49 | if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then |
| 50 | echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined" |
| 51 | echo "At least one of these environment variable is needed to run this program" |
| 52 | exit 1 |
| 53 | fi |
| 54 | fi |
| 55 | if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then |
| 56 | echo "JAVA_HOME should point to a JDK in order to run in debug mode." |
| 57 | exit 1 |
| 58 | fi |
| 59 | if [ -z "$JRE_HOME" ]; then |
| 60 | JRE_HOME="$JAVA_HOME" |
| 61 | fi |
| 62 | |
| 63 | # If we're running under jdb, we need a full jdk. |
| 64 | if [ "$1" = "debug" ] ; then |
| 65 | if [ "$os400" = "true" ]; then |
| 66 | if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then |
| 67 | echo "The JAVA_HOME environment variable is not defined correctly" |
| 68 | echo "This environment variable is needed to run this program" |
| 69 | echo "NB: JAVA_HOME should point to a JDK not a JRE" |
| 70 | exit 1 |
| 71 | fi |
| 72 | else |
| 73 | if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then |
| 74 | echo "The JAVA_HOME environment variable is not defined correctly" |
| 75 | echo "This environment variable is needed to run this program" |
| 76 | echo "NB: JAVA_HOME should point to a JDK not a JRE" |
| 77 | exit 1 |
| 78 | fi |
| 79 | fi |
| 80 | fi |
| 81 | |
| 82 | # Don't override the endorsed dir if the user has set it previously |
| 83 | if [ -z "$JAVA_ENDORSED_DIRS" ]; then |
| 84 | # Set the default -Djava.endorsed.dirs argument |
| 85 | JAVA_ENDORSED_DIRS="$CATALINA_HOME"/endorsed |
| 86 | fi |
| 87 | |
| 88 | # Set standard commands for invoking Java. |
| 89 | _RUNJAVA="$JRE_HOME"/bin/java |
| 90 | if [ "$os400" != "true" ]; then |
| 91 | _RUNJDB="$JAVA_HOME"/bin/jdb |
| 92 | fi |