mvnw 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/bin/sh
  2. # ----------------------------------------------------------------------------
  3. # Copyright 1999-2019 Seata.io Group.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # 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. # ----------------------------------------------------------------------------
  18. # Maven2 Start Up Batch script
  19. #
  20. # Required ENV vars:
  21. # ------------------
  22. # JAVA_HOME - location of a JDK home dir
  23. #
  24. # Optional ENV vars
  25. # -----------------
  26. # M2_HOME - location of maven2's installed home dir
  27. # MAVEN_OPTS - parameters passed to the Java VM when running Maven
  28. # e.g. to debug Maven itself, use
  29. # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
  30. # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
  31. # ----------------------------------------------------------------------------
  32. if [ -z "$MAVEN_SKIP_RC" ] ; then
  33. if [ -f /etc/mavenrc ] ; then
  34. . /etc/mavenrc
  35. fi
  36. if [ -f "$HOME/.mavenrc" ] ; then
  37. . "$HOME/.mavenrc"
  38. fi
  39. fi
  40. # OS specific support. $var _must_ be set to either true or false.
  41. cygwin=false;
  42. darwin=false;
  43. mingw=false
  44. case "`uname`" in
  45. CYGWIN*) cygwin=true ;;
  46. MINGW*) mingw=true;;
  47. Darwin*) darwin=true
  48. # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
  49. # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
  50. if [ -z "$JAVA_HOME" ]; then
  51. if [ -x "/usr/libexec/java_home" ]; then
  52. export JAVA_HOME="`/usr/libexec/java_home`"
  53. else
  54. export JAVA_HOME="/Library/Java/Home"
  55. fi
  56. fi
  57. ;;
  58. esac
  59. if [ -z "$JAVA_HOME" ] ; then
  60. if [ -r /etc/gentoo-release ] ; then
  61. JAVA_HOME=`java-config --jre-home`
  62. fi
  63. fi
  64. if [ -z "$M2_HOME" ] ; then
  65. ## resolve links - $0 may be a link to maven's home
  66. PRG="$0"
  67. # need this for relative symlinks
  68. while [ -h "$PRG" ] ; do
  69. ls=`ls -ld "$PRG"`
  70. link=`expr "$ls" : '.*-> \(.*\)$'`
  71. if expr "$link" : '/.*' > /dev/null; then
  72. PRG="$link"
  73. else
  74. PRG="`dirname "$PRG"`/$link"
  75. fi
  76. done
  77. saveddir=`pwd`
  78. M2_HOME=`dirname "$PRG"`/..
  79. # make it fully qualified
  80. M2_HOME=`cd "$M2_HOME" && pwd`
  81. cd "$saveddir"
  82. # echo Using m2 at $M2_HOME
  83. fi
  84. # For Cygwin, ensure paths are in UNIX format before anything is touched
  85. if $cygwin ; then
  86. [ -n "$M2_HOME" ] &&
  87. M2_HOME=`cygpath --unix "$M2_HOME"`
  88. [ -n "$JAVA_HOME" ] &&
  89. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  90. [ -n "$CLASSPATH" ] &&
  91. CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  92. fi
  93. # For Mingw, ensure paths are in UNIX format before anything is touched
  94. if $mingw ; then
  95. [ -n "$M2_HOME" ] &&
  96. M2_HOME="`(cd "$M2_HOME"; pwd)`"
  97. [ -n "$JAVA_HOME" ] &&
  98. JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
  99. # TODO classpath?
  100. fi
  101. if [ -z "$JAVA_HOME" ]; then
  102. javaExecutable="`which javac`"
  103. if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
  104. # readlink(1) is not available as standard on Solaris 10.
  105. readLink=`which readlink`
  106. if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
  107. if $darwin ; then
  108. javaHome="`dirname \"$javaExecutable\"`"
  109. javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
  110. else
  111. javaExecutable="`readlink -f \"$javaExecutable\"`"
  112. fi
  113. javaHome="`dirname \"$javaExecutable\"`"
  114. javaHome=`expr "$javaHome" : '\(.*\)/bin'`
  115. JAVA_HOME="$javaHome"
  116. export JAVA_HOME
  117. fi
  118. fi
  119. fi
  120. if [ -z "$JAVACMD" ] ; then
  121. if [ -n "$JAVA_HOME" ] ; then
  122. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  123. # IBM's JDK on AIX uses strange locations for the executables
  124. JAVACMD="$JAVA_HOME/jre/sh/java"
  125. else
  126. JAVACMD="$JAVA_HOME/bin/java"
  127. fi
  128. else
  129. JAVACMD="`which java`"
  130. fi
  131. fi
  132. if [ ! -x "$JAVACMD" ] ; then
  133. echo "Error: JAVA_HOME is not defined correctly." >&2
  134. echo " We cannot execute $JAVACMD" >&2
  135. exit 1
  136. fi
  137. if [ -z "$JAVA_HOME" ] ; then
  138. echo "Warning: JAVA_HOME environment variable is not set."
  139. fi
  140. CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
  141. # traverses directory structure from process work directory to filesystem root
  142. # first directory with .mvn subdirectory is considered project base directory
  143. find_maven_basedir() {
  144. if [ -z "$1" ]
  145. then
  146. echo "Path not specified to find_maven_basedir"
  147. return 1
  148. fi
  149. basedir="$1"
  150. wdir="$1"
  151. while [ "$wdir" != '/' ] ; do
  152. if [ -d "$wdir"/.mvn ] ; then
  153. basedir=$wdir
  154. break
  155. fi
  156. # workaround for JBEAP-8937 (on Solaris 10/Sparc)
  157. if [ -d "${wdir}" ]; then
  158. wdir=`cd "$wdir/.."; pwd`
  159. fi
  160. # end of workaround
  161. done
  162. echo "${basedir}"
  163. }
  164. # concatenates all lines of a file
  165. concat_lines() {
  166. if [ -f "$1" ]; then
  167. echo "$(tr -s '\n' ' ' < "$1")"
  168. fi
  169. }
  170. BASE_DIR=`find_maven_basedir "$(pwd)"`
  171. if [ -z "$BASE_DIR" ]; then
  172. exit 1;
  173. fi
  174. export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
  175. if [ "$MVNW_VERBOSE" = true ]; then
  176. echo $MAVEN_PROJECTBASEDIR
  177. fi
  178. MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
  179. # For Cygwin, switch paths to Windows format before running java
  180. if $cygwin; then
  181. [ -n "$M2_HOME" ] &&
  182. M2_HOME=`cygpath --path --windows "$M2_HOME"`
  183. [ -n "$JAVA_HOME" ] &&
  184. JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  185. [ -n "$CLASSPATH" ] &&
  186. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  187. [ -n "$MAVEN_PROJECTBASEDIR" ] &&
  188. MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
  189. fi
  190. WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
  191. exec "$JAVACMD" \
  192. $MAVEN_OPTS \
  193. -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
  194. "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
  195. ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"