the company recently migrated svn to git and used maven to manage the code warehouse, so a little bit of research has been done to prepare for automated continuous integration, and here's an analysis of MAVEN's command program mvn: general feeling with Tomcat startup script startup is similar to #!/bin/sh# ------------------------------------------------- ---------------------------# licensed to the apache software foundation ( ASF) under one# or more contributor license agreements. see the NOTICE file# distributed with this work for additional Information# regarding copyright ownership. the asf licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the license at## http://www.apache.org/licenses/license-2.0## unless required by applicable law or agreed to in writing,# software distributed under the license is distributed on an# "As is" BASIS, WITHOUT Warranties or conditions of any# kind, either express or implied. See the License for the# specific language governing permissions and limitations# under the license.# ------------------------------- ---------------------------------------------# ----------------------------------------------------------- -----------------# maven2 start up batch script## required env vars:# ------------------# java_home - location of a jdk home dir## optional&nBsp env vars# -----------------# m2_home - location of maven2 ' s installed home dir# maven_opts - parameters passed to the Java VM when running Maven# e.g. to Debug maven itself, use# set maven_opts=-xdebug -xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000# maven_skip_rc - flag to disable loading of mavenrc files# --------------------------- -------------------------------------------------#如果系统里有多JDK版本, you can specify java_home here, so that even if the JAVA_HOME environment variable is not this, can also be made up from here #m2_home can also be specified here, MAVEN will be generated at home directory. M2 Directory #maven_opts This is the MAVEN start parameter, interested students can study the next Java_home=/usr/java /jdk1.6.0_38if [ -z "$MAVEN _skip_rc" ] ; then if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi if [ -f "$HOME/. MAVENRC " ] ; then . " $HOME/.MAVENRC " fifi# if the environment variable Maven_ SKIP_RC exists, find out if MAVEN environment variables are set from the 3 external files below, #下面是系统环境检查, and Tomcat's startup.sh a # os specific support. $var _must_ be set to either true or false.cygwin=false; darwin=false;mingw=falsecase "' uname '" in cygwin*) cygwin=true ;; mingw*) mingw=true;; darwin*) darwin=true # # look for the apple jdks first to preserve the existing behaviour, and then look # for the new jdks provided by oracle. # if [[ -z "$JAVA _home" && -l /system/library/frameworks /javavm.framework/versions/currentjdk ]] ; then # # Apple JDKs # export java_home=/system/library/ frameworks/javavm.framework/versions/currentjdk/home fi if [[ -z "$JAVA _home" && -l /system/library/java/ javavirtualmachines/currentjdk ]] ; then # # apple jdks # export java_home=/system/library/java/ javavirtualmachines/currentjdk/contents/home fi if [[ -z "$JAVA _home" && -L "/ Library/java/javavirtualmachines/currentjdk " ]] ; then # # oracle jdks # export java_home=/library/java/javavirtualmachines/ currentjdk/contents/home fi ;; esacif [ -z "$JAVA _home" ] ; then if [ -r /etc/ Gentoo-release ] ; then java_home= ' Java-config --jre-home ' fifi# here seems to be to take care of Gentoo this operating system, in particular, belongs to adapt to the operating system code if [ -z "$M 2_home" ] ; then ## resolve links - $0 may be a link to maven ' s home prg= "$" #$0 ----Current shell name # need this for relative symlinks # test –h file file exists and is a symbolic link (same-l) while [ -h "$ PRG " ] ; do ls= ' ls -ld " $PRG "' link= ' expr "$ls" : ". *-> \ (. *\) $ ' if expr " $link " : '/.* ' > /dev/null; then prg= "$link" else prg= "' dirname " $PRG "'/$link" fi done #这个是排除软链接, find out the actual command run directory #如果有童鞋分析过tomcat的startup. Sh script, you can see that the above script is basically identical saveddir= ' pwd ' m2_home= ' dirname "$PRG" '/'. # make it fully qualified m2_home= ' cd "$M 2_home" & & pwd ' cd ' $saveddIR " # echo Using m2 at $M 2_HOMEFI#CD into the MVN application directory # for cygwin, ensure paths are in UNIX format before anything is touchedif $cygwin ; then [ -n "$M 2_home" ] && m2_home= ' cygpath --unix "$M 2_home" [ -n "$JAVA _home"  ] && java_home= ' cygpath --unix "$JAVA _home" ' [ -n "$CLASSPATH" ] && classpath= ' Cygpath --path --unix "$CLASSPATH" ' Fi# for migwn, ensure paths are in unix format before anything is touchedif $mingw ; then [ -n "$M 2_ HOME " ] && m2_home=" ' (cd "$M 2_home"; pwd) ' " [ -n "$JAVA _home" ] &Amp;& java_home= "' (cd " $JAVA _home "; pwd) '" # TODO classpath?fi# above a large string are adapted to MinGW and Cygwin environment, directly skip, the following is dry #test –z string string length is zero #如果没有设置JAVA_ HOME, the program on its own to find java_homeif [ -z "$JAVA _home" ]; then javaexecutable= "' which javac " if [ -n " $javaExecutable " -a ! " ' expr \ "$ Javaexecutable\ " : \ ([^ ]*\) '" " = " no " ]; then #test –n Length of string not 0 #test expression 1 –a expression 2 Two expressions are true #link = ' expr ' $ls : '. *-> \ (. *\) $ ' : expr after simulation ' lrwxrwxrwx 1 root root 19 3 Month 17 10:12 ./bbb.sh -> /root/shell/ test.sh ' : ' *-> \ (. *\) $ ' #很明确的发现是用expr来提取/root/shell/test.sh content #而这个循环就可以明确其目的, excludingCommand for link, find command real directory, prevent subsequent command error # readlink (1) is not available as standard on Solaris 10. #[^] # matches characters not in the specified group #上面的判读, mainly Judge Which javac, whether exists .... readlink= ' which Readlink ' if [ ! ' expr ' $readLink : ' \ ([^ ]*\) ' = "No" ]; then javaexecutable= "' readlink -f \ "$javaExecutable \" " javahome=" ' dirname \ "$javaExecutable \" ' " javahome= ' expr ' $javaHome : ' \ (. *\)/bin ' java_home= "$javaHome" export JAVA_HOME fi fifi# ifWithout setting javacmd, the script will find if [ -z "$JAVACMD" in the Java_home directory ] ; then if [ -n "$JAVA _home" ] ; then if [ -x "$JAVA _ Home/jre/sh/java " ] ; THEN      # IBM ' S JDK on AIX uses strange locations for the executables javacmd= "$JAVA _home/jre/sh/java" else javacmd= "$JAVA _home/bin/java" fi else javacmd= "' which java ' " fifi#test –x File file exists and executable #javac命令用不了, then the bird ~~~if [ ! -x "$JAVACMD" ] ; then echo "Error: java_home is" not defined correctly. " echo " We cannot execute $JAVACMD" exit 1fi# no definition java_home, the script can not find it, will be here error if [ -z "$JAVA _home" ] ; then echo "Warning: java_home environment variable is not set." Ficlassworlds_launcher=org.codehaus.plexus.classworlds.launcher.launcher# for cygwin, switch paths to Windows format before running javaif $cygwin; then [ -n "$M 2_home" ] && m2_home= ' cygpath -- path --windows "$M 2_home" [ -n "$JAVA _home" ] && java_home= ' cygpath --path --windows ' $JAVA _home "' [ -n " $ CLASSPATH " ] && classpath= ' cygpath --path --windows " $ CLASSPATH "' fi# above a bunch of code to provide variables for the following code .....exec " $JAVACMD " $MAVEN _opts -classpath "${m2_home}"/boot/plexus-classworlds-*.jar "-dclassworlds.conf=${m2_home}/bin/m2.conf" "-dmaven.home=${m2 _home} " ${CLASSWORLDS_LAUNCHER} " [email protected] "
This article is from the "Ops Road" blog, please be sure to keep this source http://vekergu.blog.51cto.com/9966832/1688387
MAVEN's command program MVN script analysis