1.创建对应的目录结构
在创建目录结构之前,首先需要创建一个项目
每创建一个Maven项目时,都需要调整jkd版本,junit版本以及删除多余的依赖
在使用idea创建项目时,目录结构可能会丢失,需要手动添加对应的目录
1-1 java源文件夹以及资源文件夹
1-2 在resources中添加不同环境下对应的配置文件
XML 文件:
通常用于描述项目的配置信息、界面布局和资源文件等。(类似于HTML)
Properties资源文件:
Properties资源文件是 键和值均为字符串的可以永久存储到文件中的key-value集合
- 本地环境下——dev
- 正式环境中——product
- 测试环境中——test
2.配置打包环境—profiles
在pom中添加配置
<!-- 打包环境配置 开发环境 测试环境 正式环境 -->
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<!-- 未指定环境时,默认打包dev环境 -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<env>product</env>
</properties>
</profile>
</profiles>
3.设置资源文件配置
存放在“
build
”中
①标注了打包的资源所在目录
②标注了哪些资源是要被获取到的
<!-- 对于项⽬资源⽂件的配置放在build中 -->
<resources>
<resource>
<directory>src/main/resources/${env}</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.tld</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
4.执行打包操作
clean compile package -Pdev -Dmaven.test.skip=true
clean
清除缓存
compile
编译
pachage
打包
-P
指定环境,找profile,找id为dev的profile
-D
=true,表示要跳过测试文件
分别写三个环境下打包的命令
打包成功后存放的地址是同一个
但每次打包不同环境的包时,内容会被覆盖掉