Maven(spring boot)多环境打包

来源:互联网 发布:vb automation error 编辑:程序博客网 时间:2024/05/01 05:53

前言

使用maven可以轻易的对项目打包,主要还是得益于maven对resources的控制非常到位,如:including,filter等等,详情可以点这里,网上花了大半会功夫理解这里;为什么说spring boot呢?maven管理用的多的还是javaEE项目,应该这样说:javaEE项目大多依靠maven进行管理,而spring boot对于多换的部署和切换做的也非常到位。

多环境

企业级软件开发测试上线过程中,需要进行四个标准环境:开发-集成测试-验收测试-上线。
- DEV 开发
- SIT 集成测试
- UAT 验收测试
- PROD 上线

解释一下sit和uat:
SIT(System Integration Testing)系统集成测试,也叫做集成测试,是软件测试的一个术语,在其中单独的软件模块被合并和作为一个组测试。它在单元测试以后和在系统测试之前。集成测试在已经被单元测试检验后进行作为它的输入模式,组织它们在更大的集合,和递送,作为它的输出,集成系统为系统测试做准备。集成测试的目的是校验功能、性能和可靠性要求,配置在主设计项目中。
因此需要在项目中配置不同的环境。

打包

打包简单一条命令解决。

 mvn clena package 

多环境打包

多环境打包,必然需要对项目进行配置,然后使用专门的打包命令进行打包。

配置

<!-- maven不同环境配置 --><profiles>        <!-- DEV -->        <profile>            <id>dev</id>            <properties>                <profiles.active>dev</profiles.active>            </properties>            <activation>                <activeByDefault>true</activeByDefault>            </activation>        </profile>        <!-- SIT -->        <profile>            <id>sit</id>            <properties>                <profiles.active>sit</profiles.active>            </properties>        </profile>        <!-- UAT -->        <profile>            <id>uat</id>            <properties>                <profiles.active>uat</profiles.active>            </properties>        </profile>        <!-- PROD -->        <profile>            <id>prod</id>            <properties>                <profiles.active>prod</profiles.active>            </properties>        </profile>    </profiles><!-- resources是对配置文件资源的处理,使用见前言部分-->    <resources>            <resource>                <excludes>                    <exclude>src/main/resources/profiles</exclude>                </excludes>                <directory>src/main/resources</directory>            </resource>            <resource>                <directory>src/main/resources/profiles/${profiles.active}</directory>            </resource>        </resources>

打包

先看看maven相关命令

-h,--help                              Display help information-am,--also-make                        构建指定模块,同时构建指定模块依赖的其他模块;-amd,--also-make-dependents            构建指定模块,同时构建依赖于指定模块的其他模块;-B,--batch-mode                        以批处理(batch)模式运行;-C,--strict-checksums                  检查不通过,则构建失败;(严格检查)-c,--lax-checksums                     检查不通过,则警告;(宽松检查)-D,--define <arg>                      Define a system property-e,--errors                            显示详细错误信息-emp,--encrypt-master-password <arg>   Encrypt master security password-ep,--encrypt-password <arg>           Encrypt server password-f,--file <arg>                        使用指定的POM文件替换当前POM文件-fae,--fail-at-end                     最后失败模式:Maven会在构建最后失败(停止)。如果Maven refactor中一个失败了,Maven会继续构建其它项目,并在构建最后报告失败。-ff,--fail-fast                        最快失败模式: 多模块构建时,遇到第一个失败的构建时停止。-fn,--fail-never                       从不失败模式:Maven从来不会为一个失败停止,也不会报告失败。-gs,--global-settings <arg>            替换全局级别settings.xml文件(Alternate path for the global settings file)-l,--log-file <arg>                    指定输出日志文件-N,--non-recursive                     仅构建当前模块,而不构建子模块(即关闭Reactor功能)。-nsu,--no-snapshot-updates             强制不更新SNAPSHOT(Suppress SNAPSHOT updates)-U,--update-snapshots                  强制更新releases、snapshots类型的插件或依赖库(否则maven一天只会更新一次snapshot依赖)-o,--offline                           运行offline模式,不联网进行依赖更新-P,--activate-profiles <arg>           激活指定的profile文件列表(用逗号[,]隔开)-pl,--projects <arg>                   手动选择需要构建的项目,项目间以逗号分隔;A project can be specified by [groupId]:artifactId or by its relative path.-q,--quiet                             安静模式,只输出ERROR-rf,--resume-from <arg>                从指定的项目(或模块)开始继续构建-s,--settings <arg>                    替换用户级别settings.xml文件(Alternate path for the user settings file)-T,--threads <arg>                     Thread count, for instance 2.0C where C is core multiplied-t,--toolchains <arg>                  Alternate path for the user toolchains file-V,--show-version                      Display version information WITHOUT stopping build-v,--version                           Display version information-X,--debug                             输出详细信息,debug模式。

-D和-P重点看一下,马上用到。

mvn clean package -Pprod#或者mvn clean package -Dprofiles.active=prod

ok 是不是prod环境,O(∩_∩)O哈哈~ 点赞啊!!!

参考文章

  • http://blog.csdn.net/kaiwii/article/details/9446243
  • http://blog.csdn.net/qq496013218/article/details/73223455
  • http://blog.csdn.net/tengxing007/article/details/75127549
原创粉丝点击