mvnw 6.3 KB

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