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