通过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
通过maven-war-plugin插件对war包分环境打包的更多相关文章
- 使用Maven分环境打包:dev sit uat prod
使用Maven管理的项目,经常需要根据不同的环境打不同的包,因为环境不同,所需要的配置文件不同,比如database的连接信息,相关属性等等. 在Maven中,我们可以通过P参数和profiles元素 ...
- springboot分环境打包(maven动态选择环境)
分环境打包核心点:spring.profiles.active pom.xml中添加: <profiles> <profile> <id>dev</id> ...
- spring-boot分环境打包为war包
1.启动类修改 @EnableSwagger2 @SpringBootApplication public class CustWebAcApplication extends SpringBootS ...
- maven release plugin插件
1.打包版本区别 SNAPSHOT 快照版本(开发阶段,不稳定,容易出现bug)RELEASE 正式版本(外部依赖使用阶段,稳定,很少出现bug)Tag :标记每次代码提交的版本(比较稳定,类似分支) ...
- spring-boot分环境打包为tar包
1.pom配置 <!-- 多环境打包 start --> <profiles> <!-- 开发环境配置 --> <profile> <id> ...
- Maven版本管理-Maven Release Plugin插件
一.什么是版本管理 首先,这里说的版本管理(version management)不是指版本控制(version control),但是本文假设你拥有基本的版本控制的知识,了解subversion的基 ...
- Maven 中maven-assembly-plugin插件的使用笔记 SpringBoot环境
首先创建一个多模块的SpringBoot项目 项目结构 父pom的内容如下: <?xml version="1.0" encoding="UTF-8"?& ...
- Maven pom.xml 添加本地jar包依赖以及打包方法
Maven项目打包时,如果遇到需要添加本地jar包依赖的时候,可以选择两种方法: 1. 安装到本地仓库 第一种方法比较常规,适用于需要添加的jar包也是由maven项目导出,含有pom文件的时候.只需 ...
- spring-boot分环境打包为jar包
1.pom配置 <!-- 多环境打包 start --> <profiles> <!-- 开发环境配置 --> <profile> <id> ...
随机推荐
- vue项目中遇到的一些问题
或访问:https://github.com/littleHiuman/experiences-about-vue 欢迎补充! vuex 状态 vue-cli 命令行 vue vue vue-rou ...
- Failed to load class "org.slf4j.impl.StaticLoggerBinder"
调试程序出现如下错误: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Default ...
- No.9 selenium学习之路之CSS定位
CSS定位方式: 元素中间加“.”表示是class 1.通过ID定位 driver.find_element_by_css_selector("#ID值") 2.通过class定位 ...
- Spring框架的基本使用(IOC部分)
Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. Spring的好处 1.方便解耦,简化开发: Spring就是一个大工厂,专门负责生成Bean,可以将所有对象创建和依赖关 ...
- AdvStringGrid 点击标题头 自动排序
- linux内核之accept实现
用户态对accept的标准用法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_size) ...
- springMVC源码分析--HttpMessageConverter写write操作(三)
上一篇博客springMVC源码分析--HttpMessageConverter参数read操作中我们已经简单介绍了参数值转换的read操作,接下来我们介绍一下返回值的处理操作.同样返回值的操作操作也 ...
- 微信小程序蓝牙模块
蓝牙部分知识 关于Service: 每个设备包含有多个Service,每个Service对应一个uuid 关于Characteristic 每个Service包含多个Characteristic,每个 ...
- nodejs mongoose populate 多层模型
参考地址:http://ronaldroe.com/populating-multiple-fields-and-levels-with-mongoose/ 文字版本 Mongoose, the po ...
- vue 单向数据流 & 双向绑定
在react中是单向数据绑定,而在vue中的特色是双向数据绑定.但是其实就我个人的理解是: 其实无论是vue还是react其实还是提倡单向数据流去管理状态,这一点在vuex和redux状态管理器上体现 ...