• maven部署方案之分离业务包


    一、思想:

    通过将业务包和公共包分离,集中管理所有包,打包时只构建业务包减少项目包的大小和传输时间。

    为了观测稳定性,暂通过环境区分,较为频繁的联调环境采用该方式,测试、预发、正式暂保持一体化打包方式不变。

    二、方法论:

    注意:如果是第一次引入依赖(有依赖变动),则需要采用默认方式,先在本地构建打包再解压,将其中lib中的所有jar放于服务器上的lib目录中。(可通过步骤二增加一个默认环境的打包方式代替)

    步骤一:配置项目启动类所在的pom如下:
    <build>
        <plugins>
            
            <plugin> 
            plugin>
        plugins>
    build>
     
    <profiles>
        <profile>
            
            
            <id>defaultid>
            <properties>
                <project.env>defaultproject.env>
            properties>
            <activation>
                <activeByDefault>trueactiveByDefault>
            activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.bootgroupId>
                        <artifactId>spring-boot-maven-pluginartifactId>
                    plugin>
                plugins>
            build>
        profile>
     
        <profile>
            
            <id>devid>
            <properties>
                <project.env>devproject.env>
            properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.bootgroupId>
                        <artifactId>spring-boot-maven-pluginartifactId>
                        <configuration>
                            <mainClass>启动类路径mainClass>
                            <layout>ZIPlayout>
                            <includes>
                                <include>
                                  直接隶属于项目的子包
                                include>
                            includes>
                        configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>repackagegoal>
                                goals>
                            execution>
                        executions>
                    plugin>
                plugins>
            build>
        profile>
    profiles>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    步骤二:jekins部署命令增加环境

    联调环境相比于默认环境需指定dev方式:clean install package -Pdev -Dmaven.test.skip=true

    步骤三:修改启动shell脚本指定lib目录

    -Dloader.path=$BASE_PATH/lib

    三、实践:

    因是第一次构建需将项目依赖包都上传至公共管理路径lib,通过maven默认构建解压后上传
    在这里插入图片描述

    步骤一:插件配置
    <build>
        <plugins>
            
            <plugin>
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.2version>
                <configuration>
                    <configurationFile>${basedir}/src/main/resources/builder/generatorConfig.xml
                    configurationFile>
                    <overwrite>trueoverwrite>
                    <verbose>trueverbose>
                configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysqlgroupId>
                        <artifactId>mysql-connector-javaartifactId>
                        <version>8.0.23version>
                        <scope>runtimescope>
                    dependency>
                    <dependency>
                        <groupId>com.baomidougroupId>
                        <artifactId>mybatis-plus-boot-starterartifactId>
                        <version>${mapper.version}version>
                    dependency>
                dependencies>
            plugin>
        plugins>
     
    build>
    <profiles>
        <profile>
            
            <id>defaultid>
            <properties>
                <project.env>defaultproject.env>
            properties>
            <activation>
                <activeByDefault>trueactiveByDefault>
            activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.bootgroupId>
                        <artifactId>spring-boot-maven-pluginartifactId>
                    plugin>
                plugins>
     
            build>
        profile>
        <profile>
            
            <id>devid>
            <properties>
                <project.env>devproject.env>
            properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.bootgroupId>
                        <artifactId>spring-boot-maven-pluginartifactId>
                        <configuration>
                            <mainClass>com.runlion.hshb.erp.HshbErpWebApplicationmainClass>
                            <layout>ZIPlayout>
                            <includes>
                                <include>
                                    <groupId>com.runlion.hshbgroupId>
                                    <artifactId>hb-erp-apiartifactId>
                                include>
                            includes>
                        configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>repackagegoal>
                                goals>
                            execution>
                        executions>
                    plugin>
                plugins>
            build>
        profile>
    profiles>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    步骤二:jekins部署命令增加环境

    联调环境相比于默认环境需指定dev方式:clean install package -Pdev -Dmaven.test.skip=true
    在这里插入图片描述

    步骤三:修改启动shell脚本指定lib目录-Dloader.path=$BASE_PATH/lib
    #!/usr/bin/env bash
    source /etc/profile
    source /app/hshb/erp/sh/constant.sh
     
    BASE_PATH=/app/hshb/erp
    PROJECT_NAME=hb-erp
    JENKINS_JOB_NAME=hshb-ci-erp
    PROFILE=$EVN_PROFILE
    DEBUG_PORT=9065
    TEMP_PATH=$BASE_PATH/artifacts/$PROJECT_NAME
     
    JAR_NAME=$PROJECT_NAME.jar
     
    echo "停止服务..."
    PID=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
    if [ -n "$PID" ]
    then
       echo "kill -9 pid:" $PID
       kill -9 $PID
    fi
     
     
     
    echo "拷贝新jar到running目录"
    cp $BASE_PATH/artifacts/$JENKINS_JOB_NAME/hb-erp-web-0.0.1-SNAPSHOT.jar $BASE_PATH/running/$JAR_NAME
     
    echo "拷贝新jar的子jar到lib目录"
    unzip -d $TEMP_PATH  $BASE_PATH/artifacts/$JENKINS_JOB_NAME/hb-erp-web-0.0.1-SNAPSHOT.jar
    mv $TEMP_PATH/BOOT-INF/lib/*   $BASE_PATH/lib/
    rm -rf  $TEMP_PATH
     
    echo "清理超过10天的日志文件..."
    cd $BASE_PATH/logs
    find $PROJECT_NAME/ -mtime +10 -name "*.log" -exec rm -rf {} \;
    rm -rf $PROJECT_NAME-running.log
     
    echo "启动服务 ..."
    cd $BASE_PATH/running
     
    nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=$DEBUG_PORT,suspend=n -Xms768m -Xmx768m   -jar -Dloader.path=$BASE_PATH/lib $JAR_NAME   --spring.profiles.active=$PROFILE >> $BASE_PATH/logs/$PROJECT_NAME-running.log 2>&1 &
     
    NEW_PID=`ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}'`
    echo "启动完成,当前服务PID=$NEW_PID"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
  • 相关阅读:
    植被冠层参数计算软件CAN-EYE的下载与安装方法
    东方博宜OJ——1004 - 【入门】编程求1*2*3*...*n
    HTML-CSS练习例子
    python Matplotlib绘制三维图
    你瞧不起的低代码开发,阿里云总裁张建锋,他看上了
    AI:09-基于深度学习的图像场景分类
    从「博客园」的困境,到「用爱发电」~
    Python 下载大文件,哪种方式速度更快
    肠道核心菌属——经黏液真杆菌属(Blautia),炎症肥胖相关的潜力菌
    Transformer是如何进军点云学习领域的?
  • 原文地址:https://blog.csdn.net/m0_37840000/article/details/128081155