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 # ---------------------------------------------------------------------------- 22 # Maven2 Start Up Batch script 23 # 24 # Required ENV vars: 25 # ------------------ 26 # JAVA_HOME - location of a JDK home dir 27 # 28 # Optional ENV vars 29 # ----------------- 30 # M2_HOME - location of maven2's installed home dir 31 # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 # e.g. to debug Maven itself, use 33 # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 # ---------------------------------------------------------------------------- 36 37 if [ -z "$MAVEN_SKIP_RC" ] ; then 38 39 if [ -f /etc/mavenrc ] ; then 40 . /etc/mavenrc 41 fi 42 43 if [ -f "$HOME/.mavenrc" ] ; then 44 . "$HOME/.mavenrc" 45 fi 46 47 fi 48 49 # OS specific support. $var _must_ be set to either true or false. 50 cygwin=false; 51 darwin=false; 52 mingw=false 53 case "`uname`" in 54 CYGWIN*) cygwin=true ;; 55 MINGW*) mingw=true;; 56 Darwin*) darwin=true 57 # 58 # Look for the Apple JDKs first to preserve the existing behaviour, and then look 59 # for the new JDKs provided by Oracle. 60 # 61 if [[ -z "$JAVA_HOME" && -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ]] ; then 62 # 63 # Apple JDKs 64 # 65 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home 66 fi 67 68 if [[ -z "$JAVA_HOME" && -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ]] ; then 69 # 70 # Apple JDKs 71 # 72 export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 73 fi 74 75 if [[ -z "$JAVA_HOME" && -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ]] ; then 76 # 77 # Oracle JDKs 78 # 79 export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 80 fi 81 ;; 82 esac 83 84 if [ -z "$JAVA_HOME" ] ; then 85 if [ -r /etc/gentoo-release ] ; then 86 JAVA_HOME=`java-config --jre-home` 87 fi 88 fi 89 90 if [ -z "$M2_HOME" ] ; then 91 ## resolve links - $0 may be a link to maven's home 92 PRG="$0" 93 94 # need this for relative symlinks 95 while [ -h "$PRG" ] ; do 96 ls=`ls -ld "$PRG"` 97 link=`expr "$ls" : '.*-> \(.*\)$'` 98 if expr "$link" : '/.*' > /dev/null; then 99 PRG="$link" 100 else 101 PRG="`dirname "$PRG"`/$link" 102 fi 103 done 104 105 saveddir=`pwd` 106 107 M2_HOME=`dirname "$PRG"`/.. 108 109 # make it fully qualified 110 M2_HOME=`cd "$M2_HOME" && pwd` 111 112 cd "$saveddir" 113 # echo Using m2 at $M2_HOME 114 fi 115 116 # For Cygwin, ensure paths are in UNIX format before anything is touched 117 if $cygwin ; then 118 [ -n "$M2_HOME" ] && 119 M2_HOME=`cygpath --unix "$M2_HOME"` 120 [ -n "$JAVA_HOME" ] && 121 JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 122 [ -n "$CLASSPATH" ] && 123 CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 124 fi 125 126 # For Migwn, ensure paths are in UNIX format before anything is touched 127 if $mingw ; then 128 [ -n "$M2_HOME" ] && 129 M2_HOME="`(cd "$M2_HOME"; pwd)`" 130 [ -n "$JAVA_HOME" ] && 131 JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 132 # TODO classpath? 133 fi 134 135 if [ -z "$JAVA_HOME" ]; then 136 javaExecutable="`which javac`" 137 if [ -n "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 138 # readlink(1) is not available as standard on Solaris 10. 139 readLink=`which readlink` 140 if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 141 javaExecutable="`readlink -f \"$javaExecutable\"`" 142 javaHome="`dirname \"$javaExecutable\"`" 143 javaHome=`expr "$javaHome" : '\(.*\)/bin'` 144 JAVA_HOME="$javaHome" 145 export JAVA_HOME 146 fi 147 fi 148 fi 149 150 if [ -z "$JAVACMD" ] ; then 151 if [ -n "$JAVA_HOME" ] ; then 152 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 153 # IBM's JDK on AIX uses strange locations for the executables 154 JAVACMD="$JAVA_HOME/jre/sh/java" 155 else 156 JAVACMD="$JAVA_HOME/bin/java" 157 fi 158 else 159 JAVACMD="`which java`" 160 fi 161 fi 162 163 if [ ! -x "$JAVACMD" ] ; then 164 echo "Error: JAVA_HOME is not defined correctly." >&2 165 echo " We cannot execute $JAVACMD" >&2 166 exit 1 167 fi 168 169 if [ -z "$JAVA_HOME" ] ; then 170 echo "Warning: JAVA_HOME environment variable is not set." 171 fi 172 173 CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 174 175 # For Cygwin, switch paths to Windows format before running java 176 if $cygwin; then 177 [ -n "$M2_HOME" ] && 178 M2_HOME=`cygpath --path --windows "$M2_HOME"` 179 [ -n "$JAVA_HOME" ] && 180 JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 181 [ -n "$CLASSPATH" ] && 182 CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 183 fi 184 185 # Provide a "standardized" way to retrieve the CLI args that will 186 # work with both Windows and non-Windows executions. 187 MAVEN_CMD_LINE_ARGS="$@" 188 export MAVEN_CMD_LINE_ARGS 189 190 exec "$JAVACMD" \ 191 $MAVEN_OPTS \ 192 -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \ 193 "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \ 194 "-Dmaven.home=${M2_HOME}" \ 195 ${CLASSWORLDS_LAUNCHER} "$@"