setclasspath.sh 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # -----------------------------------------------------------------------------
  17. # Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
  18. # are valid and consistent with the selected start-up options and set up the
  19. # endorsed directory.
  20. # -----------------------------------------------------------------------------
  21. # Make sure prerequisite environment variables are set
  22. if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then
  23. if $darwin; then
  24. # Bugzilla 54390
  25. if [ -x '/usr/libexec/java_home' ] ; then
  26. export JAVA_HOME=`/usr/libexec/java_home`
  27. # Bugzilla 37284 (reviewed).
  28. elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
  29. export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
  30. fi
  31. else
  32. JAVA_PATH=`which java 2>/dev/null`
  33. if [ "x$JAVA_PATH" != "x" ]; then
  34. JAVA_PATH=`dirname "$JAVA_PATH" 2>/dev/null`
  35. JRE_HOME=`dirname "$JAVA_PATH" 2>/dev/null`
  36. fi
  37. if [ "x$JRE_HOME" = "x" ]; then
  38. # XXX: Should we try other locations?
  39. if [ -x /usr/bin/java ]; then
  40. JRE_HOME=/usr
  41. fi
  42. fi
  43. fi
  44. if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then
  45. echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
  46. echo "At least one of these environment variable is needed to run this program"
  47. exit 1
  48. fi
  49. fi
  50. if [ -z "$JAVA_HOME" ] && [ "$1" = "debug" ]; then
  51. echo "JAVA_HOME should point to a JDK in order to run in debug mode."
  52. exit 1
  53. fi
  54. if [ -z "$JRE_HOME" ]; then
  55. JRE_HOME="$JAVA_HOME"
  56. fi
  57. # If we're running under jdb, we need a full jdk.
  58. if [ "$1" = "debug" ] ; then
  59. if [ "$os400" = "true" ]; then
  60. if [ ! -x "$JAVA_HOME"/bin/java ] || [ ! -x "$JAVA_HOME"/bin/javac ]; then
  61. echo "The JAVA_HOME environment variable is not defined correctly"
  62. echo "This environment variable is needed to run this program"
  63. echo "NB: JAVA_HOME should point to a JDK not a JRE"
  64. exit 1
  65. fi
  66. else
  67. if [ ! -x "$JAVA_HOME"/bin/java ] || [ ! -x "$JAVA_HOME"/bin/jdb ] || [ ! -x "$JAVA_HOME"/bin/javac ]; then
  68. echo "The JAVA_HOME environment variable is not defined correctly"
  69. echo "This environment variable is needed to run this program"
  70. echo "NB: JAVA_HOME should point to a JDK not a JRE"
  71. exit 1
  72. fi
  73. fi
  74. fi
  75. # Don't override the endorsed dir if the user has set it previously
  76. if [ -z "$JAVA_ENDORSED_DIRS" ]; then
  77. # Java 9 no longer supports the java.endorsed.dirs
  78. # system property. Only try to use it if
  79. # CATALINA_HOME/endorsed exists.
  80. if [ -d "$CATALINA_HOME"/endorsed ]; then
  81. JAVA_ENDORSED_DIRS="$CATALINA_HOME"/endorsed
  82. fi
  83. fi
  84. # Set standard commands for invoking Java, if not already set.
  85. if [ -z "$_RUNJAVA" ]; then
  86. _RUNJAVA="$JRE_HOME"/bin/java
  87. fi
  88. if [ "$os400" != "true" ]; then
  89. if [ -z "$_RUNJDB" ]; then
  90. _RUNJDB="$JAVA_HOME"/bin/jdb
  91. fi
  92. fi