SVN+MAVEN项目打包

题记:项目打包bash脚本

环境准备

  maven版本:3.5.2

    mvn -v  #查看maven的版本信息

  svn版本:1.4.0

    svn --version  #查看svn版本信息

 

1、update_and_package.sh脚本代码如下:

#!/bin/sh

if [ $# == 1 ]; then
        echo "[INFO] start update svn open..."

        echo " ------------------------------------------------------------------------"


        cd /home/hostname/webapps/project_name

        svn update

        echo "[INFO] success update svn open..."

        echo " ------------------------------------------------------------------------"

        echo "[INFO] start maven"

        if [ "$1" == "test" ]; then
           mvn test
        fi

        if [ "$1" == "install" ]; then
           mvn clean package -Dmaven.test.skip=true
        fi

        if [ "$1" == "package" ]; then
           mvn package -Dmaven.test.skip=true
        fi

        if [ "$1" == "clean" ]; then
           mvn clean
        fi
else
        echo "Useage: "
        echo "    ./update.sh test              Test the maven project."
        echo "    ./update.sh install           Install the maven project."
        echo "    ./update.sh package           Package the maven project."
        echo "    ./update.sh clean             Clean the maven project."
        echo "    ./update.sh compile           Compile the maven project."
fi

###注意:脚本将项目打包成jar包

2、rsync_project.sh  更新并执行jar包

#!/bin/bash
ARG=$1
VERSION=$2
date2=`date +%Y%m%d`

if [ -z $ARG ];then
        echo "Please input you operation,such as update"
        exit 3
fi

case $ARG in update)
        mkdir /home/hostname/project_name/$date2
        rsync -avz --delete 192.168.1.10::home/hostname/webapps/project_name/target/manage-0.0.1-SNAPSHOT.jar /home/hostname/webapps/$date2/manage-0.0.1-SNAPSHOT.jar
        cp -f /home/hostname/project_name/$date2/manage-0.0.1-SNAPSHOT.jar /home/hostname/project_name/webapps/manage-0.0.1-SNAPSHOT.jar
        sh /home/hostname/project_name/bin/stop.sh
        sleep 1
        sh /home/hostname/project_name/bin/start.sh
        tailf -50 /home/hostname/project_name/logs/nohup.out
                                ;;      
    *)
        echo "operation time: "$date
        ;;
    esac

3、stop.sh脚本

 

#! /bin/sh

APP_NAME=project_name.jar

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
fi

 

4、start.sh

 

#! /bin/sh

JAVA_HOME=/opt/jdk1.8.0_91

if test -n "${JAVA_HOME}"; then
  if test -z "${JAVA_EXE}"; then
    JAVA_EXE=$JAVA_HOME/bin/java
  fi
fi

if test -z "${JAVA_EXE}"; then
  JAVA_EXE=java
fi

nohup $JAVA_EXE -jar /home/hostname/project_name/webapps/project_name.jar --spring.config.name=application-outter.properties --spring.config.location=/home/hostname/project_name/webapps/application-outter.properties --logging.config=/home/hostname/peoject_name/webapps/log4j2.xml > /home/hostname/project_name/logs/nohup.out &

 

posted @ 2018-11-22 15:05  小白啊小白,Fighting  阅读(1553)  评论(0编辑  收藏  举报