Maven下载jar包时遇见的错误

时间:2022-07-11 09:11:37

  今天在学习springboot时使用thymeleaf模板时,总是报错thymeleaf.jar错误,本着想简单粗暴的解决问题,把.m2/repsitory中的jar包全部删除,在重新下载,结果惹出了更大的麻烦。以下是一些报错和解决方法

 

1.Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (execution: default-compile, phase: compile) pom.xml /a-spring line 7 Maven Project Build Lifecycle Mapping Problem

原因:这表示m2e在其执行maven的生命周期管理时没有定义该插件

解决:http://www.cnblogs.com/hzhuxin/archive/2012/06/17/2552998.html

 

2.Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-resources-plugin:jar:2.6 -> org.codehaus.plexus:plexus-utils:jar:2.0.5 (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources)

原因:解析maven-resource-plugin.jar出错,网上给出的解决方案是,在repository中找到对应的文件,然后删除,再重新使用maven下载,我试了一下没解决问题

我的解决方法:将repository中的文件删除,然后alt+f5,update maven dependencies(按理说应该先maven clean,但是使用maven clean报错download maven-clean-plugin failed),然后再maven clean,然后maven install

(PS:此方法不一定成功,我是来来回回试了好几遍才成功的,由于最近在学习spring boot,maven只是当作工具使用,并没有深究其原因)

 

3.

Description Resource Path Location Type
Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.18.1 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.18.1 from/to central (https://repo.maven.apache.org/maven2): connect timed outpom.xml/a-springline 1Maven Configuration Problem

原因同上,解决方法也同上,只不过删除相关文件后,先maven clean,再maven update 再maven install

以上问题都解决完后,maven又能正常工作了,但是新建maven有出问题了

4.maven目录结构不对

Maven下载jar包时遇见的错误

 

此解决方法很简单,按照标准目录创建文件夹即可

但是在创建完目录,编辑好java文件,运行main函数时,报错:找不到主类:XXXX

此时需要在build path中,先选中最下方的Allow output folders for source folders,然后会多出一个Output folder:XXXX,点击编辑,选中.class所在的文件夹,然后就能运行main函数了

5.找不到maven dependencies

解决:找到.class文件添加如下:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>

到此一个正常的maven 项目就能运行了

遗留问题:
1.为什么添加了一个spring-boot-starter-thymeleaf文件搞出这么多乱子
2.maven创建的项目为什么目录结构不对
3.不能直接在build path中添加maven dependenices,而是在.class中添加一串配置,肯定不是长久之计,太麻烦