Home | History | Annotate | Download | only in bin
      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 QUOTED_ARGS=""
     38 while [ "$1" != "" ] ; do
     39 
     40   QUOTED_ARGS="$QUOTED_ARGS \"$1\""
     41   shift
     42 
     43 done
     44 
     45 if [ -z "$MAVEN_SKIP_RC" ] ; then
     46 
     47   if [ -f /etc/mavenrc ] ; then
     48     . /etc/mavenrc
     49   fi
     50 
     51   if [ -f "$HOME/.mavenrc" ] ; then
     52     . "$HOME/.mavenrc"
     53   fi
     54 
     55 fi
     56 
     57 # OS specific support.  $var _must_ be set to either true or false.
     58 cygwin=false;
     59 darwin=false;
     60 mingw=false
     61 case "`uname`" in
     62   CYGWIN*) cygwin=true ;;
     63   MINGW*) mingw=true;;
     64   Darwin*) darwin=true
     65            #
     66            # Look for the Apple JDKs first to preserve the existing behaviour, and then look
     67            # for the new JDKs provided by Oracle.
     68            # 
     69            if [[ -z "$JAVA_HOME" && -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ]] ; then
     70              #
     71              # Apple JDKs
     72              #
     73              export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
     74            fi
     75            
     76            if [[ -z "$JAVA_HOME" && -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ]] ; then
     77              #
     78              # Apple JDKs
     79              #
     80              export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
     81            fi
     82              
     83            if [[ -z "$JAVA_HOME" && -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ]] ; then
     84              #
     85              # Oracle JDKs
     86              #
     87              export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
     88            fi           
     89            ;;
     90 esac
     91 
     92 if [ -z "$JAVA_HOME" ] ; then
     93   if [ -r /etc/gentoo-release ] ; then
     94     JAVA_HOME=`java-config --jre-home`
     95   fi
     96 fi
     97 
     98 if [ -z "$M2_HOME" ] ; then
     99   ## resolve links - $0 may be a link to maven's home
    100   PRG="$0"
    101 
    102   # need this for relative symlinks
    103   while [ -h "$PRG" ] ; do
    104     ls=`ls -ld "$PRG"`
    105     link=`expr "$ls" : '.*-> \(.*\)$'`
    106     if expr "$link" : '/.*' > /dev/null; then
    107       PRG="$link"
    108     else
    109       PRG="`dirname "$PRG"`/$link"
    110     fi
    111   done
    112 
    113   saveddir=`pwd`
    114 
    115   M2_HOME=`dirname "$PRG"`/..
    116 
    117   # make it fully qualified
    118   M2_HOME=`cd "$M2_HOME" && pwd`
    119 
    120   cd "$saveddir"
    121   # echo Using m2 at $M2_HOME
    122 fi
    123 
    124 # For Cygwin, ensure paths are in UNIX format before anything is touched
    125 if $cygwin ; then
    126   [ -n "$M2_HOME" ] &&
    127     M2_HOME=`cygpath --unix "$M2_HOME"`
    128   [ -n "$JAVA_HOME" ] &&
    129     JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
    130   [ -n "$CLASSPATH" ] &&
    131     CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
    132 fi
    133 
    134 # For Migwn, ensure paths are in UNIX format before anything is touched
    135 if $mingw ; then
    136   [ -n "$M2_HOME" ] &&
    137     M2_HOME="`(cd "$M2_HOME"; pwd)`"
    138   [ -n "$JAVA_HOME" ] &&
    139     JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
    140   # TODO classpath?
    141 fi
    142 
    143 if [ -z "$JAVA_HOME" ]; then
    144   javaExecutable="`which javac`"
    145   if [ -n "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
    146     # readlink(1) is not available as standard on Solaris 10.
    147     readLink=`which readlink`
    148     if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
    149       javaExecutable="`readlink -f \"$javaExecutable\"`"
    150       javaHome="`dirname \"$javaExecutable\"`"
    151       javaHome=`expr "$javaHome" : '\(.*\)/bin'`
    152       JAVA_HOME="$javaHome"
    153       export JAVA_HOME
    154     fi
    155   fi
    156 fi
    157 
    158 if [ -z "$JAVACMD" ] ; then
    159   if [ -n "$JAVA_HOME"  ] ; then
    160     if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
    161       # IBM's JDK on AIX uses strange locations for the executables
    162       JAVACMD="$JAVA_HOME/jre/sh/java"
    163     else
    164       JAVACMD="$JAVA_HOME/bin/java"
    165     fi
    166   else
    167     JAVACMD="`which java`"
    168   fi
    169 fi
    170 
    171 if [ ! -x "$JAVACMD" ] ; then
    172   echo "Error: JAVA_HOME is not defined correctly." >&2
    173   echo "  We cannot execute $JAVACMD" >&2
    174   exit 1
    175 fi
    176 
    177 if [ -z "$JAVA_HOME" ] ; then
    178   echo "Warning: JAVA_HOME environment variable is not set."
    179 fi
    180 
    181 CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
    182 
    183 # For Cygwin, switch paths to Windows format before running java
    184 if $cygwin; then
    185   [ -n "$M2_HOME" ] &&
    186     M2_HOME=`cygpath --path --windows "$M2_HOME"`
    187   [ -n "$JAVA_HOME" ] &&
    188     JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
    189   [ -n "$CLASSPATH" ] &&
    190     CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
    191 fi
    192 
    193 if [ ! -f "$YJPLIB" ]; then
    194   echo "Error: Unable to autodetect the YJP library location. Please set YJPLIB variable" >&2
    195   exit 1
    196 fi
    197 
    198 MAVEN_OPTS="-agentpath:$YJPLIB=onexit=snapshot,onexit=memory,tracing,onlylocal $MAVEN_OPTS"
    199 
    200 exec "$JAVACMD" \
    201   $MAVEN_OPTS \
    202   -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
    203   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
    204   "-Dmaven.home=${M2_HOME}"  \
    205   ${CLASSWORLDS_LAUNCHER} $QUOTED_ARGS
    206 
    207