美文网首页swift
Maven Profile多环境打包

Maven Profile多环境打包

作者: CoffeeSite | 来源:发表于2017-03-28 14:35 被阅读211次

在项目管理中,对于一个项目或者产品,我们经常会有开发,测试,预发布,生产等多套环境。为避免每次打包发布有过多的人为干扰因素,我们可以利用maven的profile来管理配置项。命令:mvn install -P dev


首选需要修改maven build的配置,添加resources的filter用于替换占位符

<build>
        <outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/classes/</outputDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>    //定义需要替换配置的文件路径
                <filtering>true</filtering>    
            </resource>
        </resources>
        <plugins></plugins>
</build>

方法一:将配置项写在mvn中

<profiles>
        <profile>
            <id>Local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- 打包配置选择 -->
                <!-- 公共配置 需要考虑是否单独配置成私有 -->
                <mvn.common.username>local</mvn.common.username>
            </properties>
        </profile>

        <profile>
            <id>Testing</id>
            <properties>
                <!-- 打包配置选择 -->
                <!-- 公共配置 需要考虑是否单独配置成私有 -->
                <mvn.common.username>testing</mvn.common.username>
            </properties>
        </profile>

        <profile>
            <id>Pro</id>
            <properties>
                <!-- 打包配置选择 -->
                <!-- 公共配置 需要考虑是否单独配置成私有 -->
                <mvn.common.username>pro</mvn.common.username>
            </properties>
        </profile>
    </profiles>

方法二:将配置项单独写在配置文件中

<profiles>
        <profile>
            <id>Local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <filters>
                    <filter>../Test.properties</filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>Testing</id>
            <build>
                <filters>
                    <filter>../Production.properties</filter>
                </filters>
            </build>
        </profile>
    </profiles>

注:
1.profiles定义了各个环境的变量id,activeByDefault定义默认打包的环境
2.resources中是定义哪些目录下的文件会被配置文件中定义的变量替换,一般我们会把项目的配置文件放在src/main/resources下,里面用到的变量在打包时就会根据filter中的变量配置替换成固定值

相关文章

  • Maven Profile多环境打包

    在项目管理中,对于一个项目或者产品,我们经常会有开发,测试,预发布,生产等多套环境。为避免每次打包发布有过多的人为...

  • maven profile 打包多环境

    说明:spring + maven 的项目结构图: 前提:spring-mvc.xml 引入.properties...

  • maven profile多环境配置

    使用maven profile实现多环境配置(代码) maven profile 实现多环境可移植构建 在开发过程...

  • Maven Profile按环境打包

    在日常开发中,我们项目的开发环境和生产环境以及测试环境往往是不同的,比如:数据库的url等。在项目上生产环境时,就...

  • 5.SpringBoot多环境配置

    maven多环境配置示例 SpringBoot多环境配置 Profile是Spring针对不同环境不同配置的支持。...

  • Maven 多环境打包以及聚合打包(一)

    说明 本文只是一个总结参考文章:Maven 插件 - 打包时多环境配置文件设置 Maven 多环境打包 mav...

  • Spring Profile

    Maven打包通过Profile来区分环境所需的配置; 1.pom.xml文件内配置: 2.application...

  • 2020-03-19 springboot 打包运行

    打包 指定profile mvn clean package -Pbeta 指定profile以maven命令的方...

  • maven多环境profile配置

    在实际开发项目中,常常有几种环境,一般情况下最少有三种环境:开发、测试、正式。 各个环境之间的参数各不相同,比如m...

  • Maven jar profile 多环境

    简言 为了减少开发人员反复修改配置,考虑在旧项目(非springboot)中使用 maven profile,在此...

网友评论

    本文标题:Maven Profile多环境打包

    本文链接:https://www.haomeiwen.com/subject/llpjottx.html