文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

④【Maven】Maven的构建命令

2023-08-30 12:46

关注

在这里插入图片描述

个人简介:Java领域新星创作者;阿里云技术博主、星级博主、专家博主;正在Java学习的路上摸爬滚打,记录学习的过程~
个人主页:.29.的博客
学习社区:进去逛一逛~

在这里插入图片描述


一、注意

运行 Maven 构建命令时,必须进入到含有 pom.xml文件的目录中。如果没有在 pom.xml 所在的目录运行 Maven 的构建命令,就会发生错误:The goal you specified requires a project to execute but there is no POM in this directory

在这里插入图片描述


二、🚀清理操作的命令

命令

mvn clean

效果

删除 target 目录
(代码为成功效果演示,可忽略…)

D:\maven-workspace\spaceVedio\pro03-maven-parent>mvn clean[INFO] Scanning for projects...[INFO] ------------------------------------------------------------------------[INFO] Reactor Build Order:[INFO][INFO] pro03-maven-parent                     [pom][INFO] pro06-maven-module                     [jar][INFO] pro05-maven-module                     [jar][INFO] pro04-maven-module                     [jar][INFO][INFO] ----------------< cpm.haojin.maven:pro03-maven-parent >-----------------[INFO] Building pro03-maven-parent 1.0-SNAPSHOT                           [1/4][INFO] --------------------------------[ pom ]---------------------------------[INFO][INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ pro03-maven-parent ---[INFO][INFO] ----------------< cpm.haojin.maven:pro06-maven-module >-----------------[INFO] Building pro06-maven-module 1.0-SNAPSHOT                           [2/4][INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ pro06-maven-module ---[INFO] Deleting D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\target[INFO][INFO] ----------------< cpm.haojin.maven:pro05-maven-module >-----------------[INFO] Building pro05-maven-module 1.0-SNAPSHOT                           [3/4][INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ pro05-maven-module ---[INFO] Deleting D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\target[INFO][INFO] ----------------< com.haojin.maven:pro04-maven-module >-----------------[INFO] Building pro04-maven-module 1.0-SNAPSHOT                           [4/4][INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ pro04-maven-module ---[INFO] Deleting D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\target[INFO] ------------------------------------------------------------------------[INFO] Reactor Summary for pro03-maven-parent 1.0-SNAPSHOT:[INFO][INFO] pro03-maven-parent ................................. SUCCESS [  0.104 s][INFO] pro06-maven-module ................................. SUCCESS [  0.024 s][INFO] pro05-maven-module ................................. SUCCESS [  0.030 s][INFO] pro04-maven-module ................................. SUCCESS [  0.030 s][INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time:  0.289 s[INFO] Finished at: 2022-11-27T12:55:29+08:00[INFO] ------------------------------------------------------------------------

三、🚀编译操作的命令

命令 - 效果

编译主程序的命令:mvn compile编译测试程序的命令:mvn test-compile

四、🚀测试操作的命令

命令

mvn test

效果
对工程中 test目录 下的程序进行测试,测试的报告放在target/surefire-reports目录


五、🚀打包操作的命令

命令

mvn package

效果

执行命令的工程会被打包成 —— jar包,得到的jar包被存放在target目录中


六、🚀安装操作的命令

命令

mvn intall

效果

将本地构建过程中生成的 jar 包存入 Maven 本地仓库。
(代码为成功效果演示,可忽略… 示例的pro03-maven-parent工程是打包方式为pom的管理子工程的工程,其与其子工程生成的jar包就会被存放到本地仓库的指定路径中去)

D:\maven-workspace\spaceVedio\pro03-maven-parent>mvn install[INFO] Scanning for projects...[INFO] ------------------------------------------------------------------------[INFO] Reactor Build Order:[INFO][INFO] pro03-maven-parent                     [pom][INFO] pro06-maven-module                     [jar][INFO] pro05-maven-module                     [jar][INFO] pro04-maven-module                     [jar][INFO][INFO] ----------------< cpm.haojin.maven:pro03-maven-parent >-----------------[INFO] Building pro03-maven-parent 1.0-SNAPSHOT                           [1/4][INFO] --------------------------------[ pom ]---------------------------------[INFO][INFO] --- maven-install-plugin:2.4:install (default-install) @ pro03-maven-parent ---[INFO] Installing D:\maven-workspace\spaceVedio\pro03-maven-parent\pom.xml to d:\maven-repository\cpm\haojin\maven\pro03-maven-parent\1.0-SNAPSHOT\pro03-maven-parent-1.0-SNAPSHOT.pom[INFO][INFO] ----------------< cpm.haojin.maven:pro06-maven-module >-----------------[INFO] Building pro06-maven-module 1.0-SNAPSHOT                           [2/4][INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pro06-maven-module ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\src\main\resources[INFO][INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ pro06-maven-module ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\target\classes[INFO][INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pro06-maven-module ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\src\test\resources[INFO][INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pro06-maven-module ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\target\test-classes[INFO][INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ pro06-maven-module ---[INFO] Surefire report directory: D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\target\surefire-reports------------------------------------------------------- T E S T S-------------------------------------------------------Running cpm.haojin.maven.AppTestTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 secResults :Tests run: 1, Failures: 0, Errors: 0, Skipped: 0[INFO][INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ pro06-maven-module ---[INFO] Building jar: D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\target\pro06-maven-module-1.0-SNAPSHOT.jar[INFO][INFO] --- maven-install-plugin:2.4:install (default-install) @ pro06-maven-module ---[INFO] Installing D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\target\pro06-maven-module-1.0-SNAPSHOT.jar to d:\maven-repository\cpm\haojin\maven\pro06-maven-module\1.0-SNAPSHOT\pro06-maven-module-1.0-SNAPSHOT.jar[INFO] Installing D:\maven-workspace\spaceVedio\pro03-maven-parent\pro06-maven-module\pom.xml to d:\maven-repository\cpm\haojin\maven\pro06-maven-module\1.0-SNAPSHOT\pro06-maven-module-1.0-SNAPSHOT.pom[INFO][INFO] ----------------< cpm.haojin.maven:pro05-maven-module >-----------------[INFO] Building pro05-maven-module 1.0-SNAPSHOT                           [3/4][INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pro05-maven-module ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\src\main\resources[INFO][INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ pro05-maven-module ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\target\classes[INFO][INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pro05-maven-module ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\src\test\resources[INFO][INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pro05-maven-module ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\target\test-classes[INFO][INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ pro05-maven-module ---[INFO] Surefire report directory: D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\target\surefire-reports------------------------------------------------------- T E S T S-------------------------------------------------------Running cpm.haojin.maven.AppTestTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 secResults :Tests run: 1, Failures: 0, Errors: 0, Skipped: 0[INFO][INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ pro05-maven-module ---[INFO] Building jar: D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\target\pro05-maven-module-1.0-SNAPSHOT.jar[INFO][INFO] --- maven-install-plugin:2.4:install (default-install) @ pro05-maven-module ---[INFO] Installing D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\target\pro05-maven-module-1.0-SNAPSHOT.jar to d:\maven-repository\cpm\haojin\maven\pro05-maven-module\1.0-SNAPSHOT\pro05-maven-module-1.0-SNAPSHOT.jar[INFO] Installing D:\maven-workspace\spaceVedio\pro03-maven-parent\pro05-maven-module\pom.xml to d:\maven-repository\cpm\haojin\maven\pro05-maven-module\1.0-SNAPSHOT\pro05-maven-module-1.0-SNAPSHOT.pom[INFO][INFO] ----------------< com.haojin.maven:pro04-maven-module >-----------------[INFO] Building pro04-maven-module 1.0-SNAPSHOT                           [4/4][INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pro04-maven-module ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\src\main\resources[INFO][INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ pro04-maven-module ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\target\classes[INFO][INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pro04-maven-module ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\src\test\resources[INFO][INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pro04-maven-module ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\target\test-classes[INFO][INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ pro04-maven-module ---[INFO] Surefire report directory: D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\target\surefire-reports------------------------------------------------------- T E S T S-------------------------------------------------------Running com.haojin.maven.AppTestTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 secResults :Tests run: 1, Failures: 0, Errors: 0, Skipped: 0[INFO][INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ pro04-maven-module ---[INFO] Building jar: D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\target\pro04-maven-module-1.0-SNAPSHOT.jar[INFO][INFO] --- maven-install-plugin:2.4:install (default-install) @ pro04-maven-module ---[INFO] Installing D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\target\pro04-maven-module-1.0-SNAPSHOT.jar to d:\maven-repository\com\haojin\maven\pro04-maven-module\1.0-SNAPSHOT\pro04-maven-module-1.0-SNAPSHOT.jar[INFO] Installing D:\maven-workspace\spaceVedio\pro03-maven-parent\pro04-maven-module\pom.xml to d:\maven-repository\com\haojin\maven\pro04-maven-module\1.0-SNAPSHOT\pro04-maven-module-1.0-SNAPSHOT.pom[INFO] ------------------------------------------------------------------------[INFO] Reactor Summary for pro03-maven-parent 1.0-SNAPSHOT:[INFO][INFO] pro03-maven-parent ................................. SUCCESS [  0.171 s][INFO] pro06-maven-module ................................. SUCCESS [  1.400 s][INFO] pro05-maven-module ................................. SUCCESS [  0.370 s][INFO] pro04-maven-module ................................. SUCCESS [  0.410 s][INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time:  2.452 s[INFO] Finished at: 2022-11-27T13:18:56+08:00[INFO] ------------------------------------------------------------------------

——————————

被存放的 jar 包在 Maven 仓库中的路径是根据它的坐标生成的:

  <groupId>cpm.haojin.maven</groupId>  <artifactId>pro04-maven-module</artifactId>  <version>1.0-SNAPSHOT</version>
D:\maven-repository\com\haojin\maven\pro04-maven-module\1.0-SNAPSHOT\pro04-maven-module-1.0-SNAPSHOT.jar

在这里插入图片描述


在这里插入图片描述

来源地址:https://blog.csdn.net/ebb29bbe/article/details/128055704

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-人工智能
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯