> 文章列表 > maven 打包实践

maven 打包实践

maven 打包实践

Maven的打包操作
对于企业级项目,无论是进行本地测试,还是测试环境测试以及最
终的项目上线,都会涉及项目的打包操作。对于每个环境下的项目
打包,对应的项目所需要的配置资源都会有所区别,实现打包的方
式有很多种,可以通过ant,或者通过idea 自带的打包功能实现项
目打包,但当项目很大并且需要的外界配置很多时,此时打包的配
置就会异常复杂,对于maven 项目,我们可以用过 pom.xml 配置
的方式来实现打包时的环境选择,相比较其他形式打包工具,通过
maven 只需要通过简单的配置,就可以轻松完成不同环境下项目的
整体打包。
比如下面这样一个项目,项目中配置了不同环境下项目所需要的配
置文件,这时候需要完成不同环境下的打包操作,此时通过修改
pom.xml 如下:

添加Profile配置

<!-- 打包环境配置 开发环境 测试环境 正式环境 -->
<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>

设置资源文件配置

 执行打包操作
打开Run/Debug Configuarations窗口,输入对应的打包命令
此时对应打包命令
1. clean compile package -Dmaven.test.skip=true
打包默认环境(开发环境)并且跳过maven 测试操作
2. clean compile package -Ptest -Dmaven.test.skip=true
打包测试环境并且跳过maven 测试操作
3. clean compile package -Pproduct -
Dmaven.test.skip=true
打包生产环境并且跳过maven 测试操作

maven打包截图