今天在创建新项目时,由于手误,出现了一个bug:must be “pom” but is “jar”,信息图如下: 整个项目结构为: 也就是code-ac的pom.xml的packaging应该是pom,但是在xml中未明确指定packaging,所以默认使用的是jar,因此出现了上面的bug。
解决办法:
在code-ac的pom.xml文件中指定packaging为pom即可。如果修改之后仍然继续报错,那么就把磁盘上的本地maven库中项目响应的包删除掉,也就是把缓存删除掉,即可。
拓展:
Q: 为什么在未指定packaging的时候,默认使用的是jar类型?
A: 查看maven.jar中目录下的/schemas/maven-4.0.0.xsd文件,搜索packaging,或者直接从pom.xml中点击<packaging>标签跳转过去,会发现packaging的定义信息中指定了default就是jar
<xs:element name="packaging" minOccurs="0" type="xs:string" default="jar"> <xs:annotation> <xs:documentation source="version">4.0.0</xs:documentation> <xs:documentation source="description"> The type of artifact this project produces, for example <code>jar</code> <code>war</code> <code>ear</code> <code>pom</code>. Plugins can create their own packaging, and therefore their own packaging types, so this list does not contain all possible types. </xs:documentation> </xs:annotation> </xs:element>