Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
771 blopes 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
 
24
# Make sure prerequisite environment variables are set
25
if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then
26
  if $darwin; then
27
    # Bugzilla 54390
28
    if [ -x '/usr/libexec/java_home' ] ; then
29
      export JAVA_HOME=`/usr/libexec/java_home`
30
    # Bugzilla 37284 (reviewed).
31
    elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
32
      export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
33
    fi
34
  else
35
    JAVA_PATH=`which java 2>/dev/null`
36
    if [ "x$JAVA_PATH" != "x" ]; then
37
      JAVA_PATH=`dirname "$JAVA_PATH" 2>/dev/null`
38
      JRE_HOME=`dirname "$JAVA_PATH" 2>/dev/null`
39
    fi
40
    if [ "x$JRE_HOME" = "x" ]; then
41
      # XXX: Should we try other locations?
42
      if [ -x /usr/bin/java ]; then
43
        JRE_HOME=/usr
44
      fi
45
    fi
46
  fi
47
  if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then
48
    echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
49
    echo "At least one of these environment variable is needed to run this program"
50
    exit 1
51
  fi
52
fi
53
if [ -z "$JAVA_HOME" ] && [ "$1" = "debug" ]; then
54
  echo "JAVA_HOME should point to a JDK in order to run in debug mode."
55
  exit 1
56
fi
57
 
58
# If we're running under jdb, we need a full jdk.
59
if [ "$1" = "debug" ] ; then
60
  if [ "$os400" = "true" ]; then
61
    if [ ! -x "$JAVA_HOME"/bin/java ] || [ ! -x "$JAVA_HOME"/bin/javac ]; then
62
      echo "The JAVA_HOME environment variable is not defined correctly"
63
      echo "JAVA_HOME=$JAVA_HOME"
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 ] || [ ! -x "$JAVA_HOME"/bin/jdb ] || [ ! -x "$JAVA_HOME"/bin/javac ]; then
70
      echo "The JAVA_HOME environment variable is not defined correctly"
71
      echo "JAVA_HOME=$JAVA_HOME"
72
      echo "This environment variable is needed to run this program"
73
      echo "NB: JAVA_HOME should point to a JDK not a JRE"
74
      exit 1
75
    fi
76
  fi
77
fi
78
 
79
if [ -z "$JRE_HOME" ]; then
80
  # JAVA_HOME_MUST be set
81
  if [ ! -x "$JAVA_HOME"/bin/java ]; then
82
    echo "The JAVA_HOME environment variable is not defined correctly"
83
    echo "JAVA_HOME=$JAVA_HOME"
84
    echo "This environment variable is needed to run this program"
85
    echo "NB: JAVA_HOME should point to a JDK not a JRE"
86
    exit 1
87
  fi
88
  JRE_HOME="$JAVA_HOME"
89
else
90
  if [ ! -x "$JRE_HOME"/bin/java ]; then
91
    echo "The JRE_HOME environment variable is not defined correctly"
92
    echo "JRE_HOME=$JRE_HOME"
93
    echo "This environment variable is needed to run this program"
94
    exit 1
95
  fi
96
fi
97
 
98
# Don't override the endorsed dir if the user has set it previously
99
if [ -z "$JAVA_ENDORSED_DIRS" ]; then
100
  # Java 9 no longer supports the java.endorsed.dirs
101
  # system property. Only try to use it if
102
  # CATALINA_HOME/endorsed exists.
103
  if [ -d "$CATALINA_HOME"/endorsed ]; then
104
    JAVA_ENDORSED_DIRS="$CATALINA_HOME"/endorsed
105
  fi
106
fi
107
 
108
# Set standard commands for invoking Java, if not already set.
109
if [ -z "$_RUNJAVA" ]; then
110
  _RUNJAVA="$JRE_HOME"/bin/java
111
fi
112
if [ "$os400" != "true" ]; then
113
  if [ -z "$_RUNJDB" ]; then
114
    _RUNJDB="$JAVA_HOME"/bin/jdb
115
  fi
116
fi