大家好,又见面了,我是你们的朋友全栈君。
Maven 打包问题
- 1、问题描述
- 2、问题分析
- 3、问题解决
- 4、总结
1、问题描述
今天给聚合工程统一打包时出现这样一个异常packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109
。完整异常如下:
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project cn.edu.njust:mango_pom:1.0-SNAPSHOT (D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_pompom.xml) has 1 error
[ERROR] 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
Process finished with exit code 1
2、问题分析
出错的pom.xml
文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.edu.njust</groupId>
<artifactId>mango_pom</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>../mango_common</module>
<module>../mango_core</module>
<module>../mango</module>
</modules>
</project>
这是由于统一打包的工程不生成jar
包文件,所以需要使用pom
格式打包,即<packaging>pom</packaging>
。完整正确pom.xml
文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<groupId>cn.edu.njust</groupId>
<artifactId>mango_pom</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>../mango_common</module>
<module>../mango_core</module>
<module>../mango</module>
</modules>
</project>
3、问题解决
运行程序,结果输出如下:
代码语言:javascript复制[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] mango-common [jar]
[INFO] mango_core [jar]
[INFO] mango [jar]
[INFO] mango_pom [pom]
[INFO]
[INFO] ---------------------< cn.edu.njust:mango-common >----------------------
[INFO] Building mango-common 1.0-SNAPSHOT [1/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mango-common ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mango-common ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mango-common ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_commonsrctestresources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mango-common ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mango-common ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mango-common ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mango-common ---
[INFO] Installing D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_commontargetmango-common-1.0-SNAPSHOT.jar to D:nanligongprogramjavamavenreposcnedunjustmango-common1.0-SNAPSHOTmango-common-1.0-SNAPSHOT.jar
[INFO] Installing D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_commonpom.xml to D:nanligongprogramjavamavenreposcnedunjustmango-common1.0-SNAPSHOTmango-common-1.0-SNAPSHOT.pom
[INFO]
[INFO] ----------------------< cn.edu.njust:mango_core >-----------------------
[INFO] Building mango_core 1.0-SNAPSHOT [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mango_core ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mango_core ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mango_core ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_coresrctestresources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mango_core ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mango_core ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mango_core ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mango_core ---
[INFO] Installing D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_coretargetmango_core-1.0-SNAPSHOT.jar to D:nanligongprogramjavamavenreposcnedunjustmango_core1.0-SNAPSHOTmango_core-1.0-SNAPSHOT.jar
[INFO] Installing D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_corepom.xml to D:nanligongprogramjavamavenreposcnedunjustmango_core1.0-SNAPSHOTmango_core-1.0-SNAPSHOT.pom
[INFO]
[INFO] -------------------------< cn.edu.njust:mango >-------------------------
[INFO] Building mango 0.0.1-SNAPSHOT [3/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ mango ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 12 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ mango ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ mango ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mangosrctestresources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ mango ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ mango ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ mango ---
[INFO] Building jar: D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mangotargetmango-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.6.RELEASE:repackage (repackage) @ mango ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ mango ---
[INFO] Installing D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mangotargetmango-0.0.1-SNAPSHOT.jar to D:nanligongprogramjavamavenreposcnedunjustmango .0.1-SNAPSHOTmango-0.0.1-SNAPSHOT.jar
[INFO] Installing D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mangopom.xml to D:nanligongprogramjavamavenreposcnedunjustmango .0.1-SNAPSHOTmango-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] -----------------------< cn.edu.njust:mango_pom >-----------------------
[INFO] Building mango_pom 1.0-SNAPSHOT [4/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mango_pom ---
[INFO] Installing D:nanligongmianshiproject20200505fuxispringcloudprojectmongo_back02mango_pompom.xml to D:nanligongprogramjavamavenreposcnedunjustmango_pom1.0-SNAPSHOTmango_pom-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] mango-common ....................................... SUCCESS [ 1.477 s]
[INFO] mango_core ......................................... SUCCESS [ 0.045 s]
[INFO] mango 0.0.1-SNAPSHOT ............................... SUCCESS [ 3.562 s]
[INFO] mango_pom 1.0-SNAPSHOT ............................. SUCCESS [ 0.009 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.091 s
[INFO] Finished at: 2020-05-06T13:06:40 08:00
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "nexus" could not be activated because it does not exist.
Process finished with exit code 0
打包成功!
4、总结
书上的代码直接运行绝大部分是对的,但是总有一些软件的更新使得作者无能为力。之前的API是对的,但是之后就废弃了或修改了是常有的事。所以我们需要跟踪源代码。这只是一个小小的问题,如果没有前辈的无私奉献,很难想象我们自己一天能学到多少内容。感谢各位前辈的辛勤付出,让我们少走了很多的弯路!
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/142860.html原文链接:https://javaforall.cn