• 通过maven-war-plugin插件对war包分环境打包


    针对多环节,从源头打包入手,当然这些都可以在运维阶段用脚本进行替换来代替

    resources/environment/下有四个环境,local本地、dev开发、test测试、pre预上线、prod生产,打包命令如下:

        # 本地
        mvn clean package -P local
        # 开发
        mvn clean package -P dev
        # 测试
        mvn clean package -P test
        # 预上线
        mvn clean package -P pre
        # 生产
        mvn clean package -p prod

    说明:每个环境的文件夹下的配置文件可以全量放,也可以试增量,最终会覆盖

    项目目录如下所示:

    部分POM如下说是:

        <profiles>
            <!-- 本地环境 -->
            <profile>
                <id>local</id>
                <properties>
                    <package.environment>local</package.environment>
                </properties>
                <!-- 是否默认 -->
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
            </profile>
            <!-- 开发环境 -->
            <profile>
                <id>dev</id>
                <properties>
                    <package.environment>dev</package.environment>
                </properties>
            </profile>
            <profile>
                <!-- 测试环境 -->
                <id>test</id>
                <properties>
                    <package.environment>test</package.environment>
                </properties>
            </profile>
            <profile>
                <!-- 预上线 -->
                <id>pre</id>
                <properties>
                    <package.environment>pre</package.environment>
                </properties>
            </profile>
            <profile>
                <!-- 生产环境 -->
                <id>prod</id>
                <properties>
                    <package.environment>prod</package.environment>
                </properties>
            </profile>
        </profiles>
    
        <build>
            <finalName>ssm-framework</finalName>
            <plugins>
                
                <!-- war包打包组件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${maven-war-plugin.version}</version>
                    <configuration>
                        <webResources>
                            <resource>
                                <!-- 元配置文件的目录,相对于pom.xml文件的路径 -->
                                <directory>src/main/webapp/WEB-INF</directory>
                                <!-- 是否过滤文件,也就是是否启动auto-config的功能 -->
                                <filtering>true</filtering>
                                <!-- 目标路径 -->
                                <targetPath>WEB-INF</targetPath>
                            </resource>
                            <resource>
                                <directory>src/main/resources/environment/${package.environment}</directory>
                                <targetPath>WEB-INF/classes</targetPath>
                                <filtering>true</filtering>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>

    说明:标红部分

    示例工程:https://github.com/easonjim/ssm-framework

  • 相关阅读:
    C# 之泛型详解
    C#方法的六种参数,值参数、引用参数、输出参数、参数数组、命名参数、可选参数
    在C#中理解和实现策略模式的绝对入门教程
    负载均衡的原理
    C#多线程编程
    深入研究虚幻4反射系统实现原理(二)
    深入研究虚幻4反射系统实现原理(一)
    虚幻4属性系统(反射)翻译
    UE4中使用数据表(Data Table)
    UE4 自定义物理表面类型(Surface Type)
  • 原文地址:https://www.cnblogs.com/EasonJim/p/9126442.html
Copyright © 2020-2023  润新知