linux 下编译与发布jar包 ---主要用在本地开发环境
我们的代码在git上,然后通过如下命令进行下载与编译。
编译后,运行我们执行的jar包
build-demo.sh --- git下载代码到本地、maven发布包
restart-demo-mock.sh ---在本机器上运行
CODE_PATH="code" =============打包编译到前目录的code目录下
PROJECT_NAME="ccjr-demo" ===========git仓库地址
PROJECT_BRANCH="develop" ============切换到编译的分支
GIT_ADDR="http://git地址/server/$PROJECT_NAME.git" ==========下载git仓库地址
[root@localhost system]# vi build-demo.sh #!/bin/bash CODE_PATH="code" PROJECT_NAME="ccjr-demo" PROJECT_BRANCH="develop" GIT_ADDR="http://git地址/server/$PROJECT_NAME.git" OLD_PATH=`pwd` LINK_PATH=`readlink $0` [ "x" = "x$LINK_PATH" ] && CURRENT_PATH=`dirname $0` [ "x" != "x$LINK_PATH" ] && CURRENT_PATH=`dirname $LINK_PATH` cd $CURRENT_PATH CURRENT_PATH=`pwd` #判断文件夹是否存在 -d if [[ ! -d $CURRENT_PATH/$CODE_PATH/$PROJECT_NAME ]]; then mkdir -p $CURRENT_PATH/$CODE_PATH cd $CURRENT_PATH/$CODE_PATH git clone $GIT_ADDR cd $CURRENT_PATH/$CODE_PATH/$PROJECT_NAME git checkout $PROJECT_BRANCH fi cd $CURRENT_PATH/$CODE_PATH/$PROJECT_NAME git pull mvn clean install -DskipTests=true -s $CURRENT_PATH/settings.xml
APP_ROOT="ccjr-demo" ======项目代码目录
APP_NAME="ccjr-demo-mock" =======运行的jar包工程
EUREKA_IP="192.168.1.333" ========注册中心地址
CODE_PATH="code" ======代码目录
[root@localhost system]# vi restart-demo-mock.sh #!/bin/bash OLD_PATH=`pwd` LINK_PATH=`readlink $0` [ "x" = "x$LINK_PATH" ] && CURRENT_PATH=`dirname $0` [ "x" != "x$LINK_PATH" ] && CURRENT_PATH=`dirname $LINK_PATH` cd $CURRENT_PATH CURRENT_PATH=`pwd` APP_ROOT="ccjr-demo" APP_NAME="ccjr-demo-mock" EUREKA_IP="192.168.1.333" CODE_PATH="code" JAR_FILE=$APP_NAME-0.0.1-SNAPSHOT.jar TARGET_PATH=$CURRENT_PATH/$CODE_PATH/$APP_ROOT/$APP_NAME/target LOG_FILE=$APP_NAME/$APP_NAME.log RUN_PATH=$CURRENT_PATH/run/run-$APP_NAME RUN_JAR=$RUN_PATH/$JAR_FILE jps | grep $JAR_FILE [ $? -eq 0 ] && jps | grep $JAR_FILE | awk '{print $1}' |xargs kill -9 mkdir $RUN_PATH > /dev/null 2>&1 rm -rf $RUN_PATH/* > /dev/null 2>&1 cp $TARGET_PATH/$JAR_FILE $RUN_PATH/$JAR_FILE [ ! -f $RUN_JAR ] && echo "not exist $RUN_JAR" && exit 0 cd $RUN_PATH nohup java -Deureka.ip=$EUREKA_IP -Dspring.profiles.active=dev -jar $RUN_JAR > /dev/null 2>&1 & cd $CURRENT_PATH echo "##############################################" jps echo "##############################################" tail -f /home/logs/$LOG_FILE