赞
踩
如果在项目的pom.xml文件中没有指明打包类型,则默认打成jar包。使用maven命令 mvn clean package进行项目的打包,可看到如下输出结果:
- [INFO] Results:
- [INFO]
- [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
- [INFO]
- [INFO]
- [INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ springboot ---
- [INFO] Building jar: D:\Spring\springboot\target\springboot-0.0.1-SNAPSHOT.jar
- [INFO]
- [INFO] --- spring-boot-maven-plugin:2.1.6.RELEASE:repackage (repackage) @ springboot ---
- [INFO] Replacing main artifact with repackaged archive
- [INFO] ------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO] ------------------------------------------------------------------------
- [INFO] Total time: 16.318 s
- [INFO] Finished at: 2019-07-25T22:42:05+08:00
- [INFO] Final Memory: 35M/252M
- [INFO] ------------------------------------------------------------------------
可以看到 maven-jar-plugin:3.1.2:jar (default-jar) @ springboot 其实就是利用jar插件将项目打成了springboot-0.0.1-SNAPSHOT.jar,该文件会存放在target目录下。
如果要让其他的maven项目直接引用这个jar包,还要执行mvn clean install命令,输出结果为:
- [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
- [INFO]
- [INFO]
- [INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ springboot ---
- [INFO] Building jar: D:\Spring\springboot\target\springboot-0.0.1-SNAPSHOT.jar
- [INFO]
- [INFO] --- spring-boot-maven-plugin:2.1.6.RELEASE:repackage (repackage) @ springboot ---
- [INFO] Replacing main artifact with repackaged archive
- [INFO]
- [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ springboot ---
- [INFO] Installing D:\Spring\springboot\target\springboot-0.0.1-SNAPSHOT.jar to D:\Spring\maven-space
- \repository\com\example\springboot\0.0.1-SNAPSHOT\springboot-0.0.1-SNAPSHOT.jar
- [INFO] Installing D:\Spring\springboot\pom.xml to D:\Spring\maven-space\repository\com\example\sprin
- gboot\0.0.1-SNAPSHOT\springboot-0.0.1-SNAPSHOT.pom
- [INFO] ------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO] ------------------------------------------------------------------------
- [INFO] Total time: 18.514 s
- [INFO] Finished at: 2019-07-25T22:53:22+08:00
- [INFO] Final Memory: 35M/261M
- [INFO] ------------------------------------------------------------------------
在打包之后,我们又执行了安装任务install:install,从输出我们看到该任务将项目输出的jar安装到了Maven本地仓库中,我们可以打开相应的文件夹看到项目的pom和jar。只有将项目的构件安装到本地仓库之后,其他Maven项目才能使用它。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。