Maven常用命令

一、常用命令:

二、 命令参数:

上 ⾯ 列举的只是 ⽐ 较通 ⽤ 的命令,其实很多命令都可以携带参数以执 ⾏ 更精准的任务。

1. -D 传⼊属性参数

例如:
mvn package -Dmaven.test.skip=true
以 -D 开头,将 maven.test.skip 的值设为 true , 就是告诉 maven 打包的时候跳过单元测试。同
理, mvn deploy-Dmaven.test.skip=true 代表部署项 ⽬ 并跳过单元测试。

2. -P 使⽤指定的Profile配置

⽐ 如项 ⽬ 开发需要有多个环境, ⼀ 般为开发,测试,预发,正式 4 个环境,在 pom.xml 中的配置如
下:
<profiles>
<profile>
<id> dev </id>
<properties>
<env> dev </env>
</properties>
<activation>
<activeByDefault> true </activeByDefault>
</activation>
</profile>
<profile>
<id> qa </id>
<properties>
<env> qa </env>
</properties>
</profile>
<profile>
<id> pre </id>
<properties>
<env> pre </env>
</properties>
</profile>
<profile>
<id> prod </id>
<properties>
<env> prod </env>
</properties>
</profile>
</profiles>
......
<build>
<filters>
<filter> config/${env}.properties </filter>
</filters>
<resources>
<resource>
<directory> src/main/resources </directory>
<filtering> true </filtering>
</resource>
</resources>
......
</build>
profiles 定义了各个环境的变量 id , filters 中定义了变量配置 ⽂ 件的地址,其中地址中的环境
变量就是上 ⾯ profile 中定义的值, resources 中是定义哪些 ⽬ 录下的 ⽂ 件会被配置 ⽂ 件中定义的变
量替换。
通过 maven 可以实现按不同环境进 ⾏ 打包部署,例如:
mvn package -Pdev -Dmaven.test.skip=true
表示打包本地环境,并跳过单元测试

相关推荐
介一安全15 小时前
BurpSuite 插件 Log4j2Scan 使用和手动验证
测试工具·log4j·安全性测试
前路不黑暗@16 小时前
Java项目:Java脚手架项目的地图服务(十)
java·数据库·spring boot·笔记·学习·spring cloud·maven
没有bug.的程序员19 小时前
Maven 进阶进阶:依赖优化内核、多模块构建艺术与“依赖地狱”自愈指南
java·maven·构建·多模块·依赖优化
前路不黑暗@20 小时前
Java项目:Java脚手架项目通用基类和常量类的封装(九)
java·spring boot·笔记·学习·spring cloud·maven·intellij-idea
AC赳赳老秦20 小时前
软件组件自动化的革命:DeepSeek 引领高效开发新时代
运维·人工智能·算法·云原生·maven·devops·deepseek
前路不黑暗@1 天前
Java项目:Java脚手架项目的地图的POJO
android·java·开发语言·spring boot·学习·spring cloud·maven
vortex51 天前
在 Apache 中完整开启 .shtml (SSI) 解析
apache
dfyx9992 天前
Maven Spring框架依赖包
java·spring·maven
xj198603192 天前
maven导入spring框架
数据库·spring·maven
鸽芷咕2 天前
时序数据库选型解析及Apache IoTDB技术实践
apache·时序数据库·iotdb