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
11 # http://www.apache.org/licenses/LICENSE-2.0
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
19 # ----------------------------------------------------------------------------
21 # ----------------------------------------------------------------------------
22 # Maven2 Start Up Batch script
26 # JAVA_HOME - location of a JDK home dir
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 # ----------------------------------------------------------------------------
37 if [ -z "$MAVEN_SKIP_RC" ] ; then
39 if [ -f /etc/mavenrc ] ; then
43 if [ -f "$HOME/.mavenrc" ] ; then
49 # OS specific support. $var _must_ be set to either true or false.
54 CYGWIN*) cygwin=true ;;
58 # Look for the Apple JDKs first to preserve the existing behaviour, and then look
59 # for the new JDKs provided by Oracle.
61 if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
65 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
68 if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
72 export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
75 if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
79 export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
82 if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
86 export JAVA_HOME=`/usr/libexec/java_home`
91 if [ -z "$JAVA_HOME" ] ; then
92 if [ -r /etc/gentoo-release ] ; then
93 JAVA_HOME=`java-config --jre-home`
97 if [ -z "$M2_HOME" ] ; then
98 ## resolve links - $0 may be a link to maven's home
101 # need this for relative symlinks
102 while [ -h "$PRG" ] ; do
104 link=`expr "$ls" : '.*-> \(.*\)$'`
105 if expr "$link" : '/.*' > /dev/null; then
108 PRG="`dirname "$PRG"`/$link"
114 M2_HOME=`dirname "$PRG"`/..
116 # make it fully qualified
117 M2_HOME=`cd "$M2_HOME" && pwd`
120 # echo Using m2 at $M2_HOME
123 # For Cygwin, ensure paths are in UNIX format before anything is touched
126 M2_HOME=`cygpath --unix "$M2_HOME"`
127 [ -n "$JAVA_HOME" ] &&
128 JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
129 [ -n "$CLASSPATH" ] &&
130 CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
133 # For Migwn, ensure paths are in UNIX format before anything is touched
136 M2_HOME="`(cd "$M2_HOME"; pwd)`"
137 [ -n "$JAVA_HOME" ] &&
138 JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
142 if [ -z "$JAVA_HOME" ]; then
143 javaExecutable="`which javac`"
144 if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
145 # readlink(1) is not available as standard on Solaris 10.
146 readLink=`which readlink`
147 if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
149 javaHome="`dirname \"$javaExecutable\"`"
150 javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
152 javaExecutable="`readlink -f \"$javaExecutable\"`"
154 javaHome="`dirname \"$javaExecutable\"`"
155 javaHome=`expr "$javaHome" : '\(.*\)/bin'`
156 JAVA_HOME="$javaHome"
162 if [ -z "$JAVACMD" ] ; then
163 if [ -n "$JAVA_HOME" ] ; then
164 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
165 # IBM's JDK on AIX uses strange locations for the executables
166 JAVACMD="$JAVA_HOME/jre/sh/java"
168 JAVACMD="$JAVA_HOME/bin/java"
171 JAVACMD="`which java`"
175 if [ ! -x "$JAVACMD" ] ; then
176 echo "Error: JAVA_HOME is not defined correctly." >&2
177 echo " We cannot execute $JAVACMD" >&2
181 if [ -z "$JAVA_HOME" ] ; then
182 echo "Warning: JAVA_HOME environment variable is not set."
185 CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
187 # For Cygwin, switch paths to Windows format before running java
190 M2_HOME=`cygpath --path --windows "$M2_HOME"`
191 [ -n "$JAVA_HOME" ] &&
192 JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
193 [ -n "$CLASSPATH" ] &&
194 CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
197 # traverses directory structure from process work directory to filesystem root
198 # first directory with .mvn subdirectory is considered project base directory
199 find_maven_basedir() {
202 while [ "$wdir" != '/' ] ; do
203 if [ -d "$wdir"/.mvn ] ; then
207 wdir=$(cd "$wdir/.."; pwd)
212 # concatenates all lines of a file
215 echo "$(tr -s '\n' ' ' < "$1")"
219 export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
220 MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
222 # Provide a "standardized" way to retrieve the CLI args that will
223 # work with both Windows and non-Windows executions.
224 MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
225 export MAVEN_CMD_LINE_ARGS
227 WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
231 -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
232 "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
233 ${WRAPPER_LAUNCHER} "$@"