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