天天看点

maven常见问题总结

问题1:

Failure to transfer org.apache.poi:poi-ooxml-schemas:jar:3.10.1 from

http://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.poi:poi-ooxml-schemas:jar:3.10.1 from/to central (http://repo.maven.apache.org/maven2):

Connection reset。

这句话的意思是: 对于这个包从maven中心传输到本地仓库失败,决定不会重新尝试下载jar包,直到mavne再改更新索引,或强制更新。

实际的解决办法是:直接去本地仓库(local repository),把这个org.apache.poi存放的目录删除掉(因为包没有下载下来),

(1)刷新你的项目(在项目上点右键–>刷新);

(2)在你的项目上右击,选择maven—>update(刷新Maven配置)就可以了,让maven重新下载;

(3)编译maven项目。在项目上点右键–>Run As –>Maven build

使用说明:

如果pom.xml中配置的jar不能下载,提示pom.xml中报错,反复使用(1)和(2)操作;

如果pom.xml文件没有报错,就使用(3)来处理;

问题2:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war

(default-war) on project prospringmvc01: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) ->

The container ‘Maven Dependencies’ references non existing library

‘E:\m2e\repository\org\apache\httpcomponents\httpclient\4.5.2\httpclient-4.5.2.jar’

在更新依赖包是由于网络问题没有更新成功经常会出现依赖包找不到的问题,此时通过浏览器去私服页面查看,发现依赖包坐标是存在的,对应的文件(比如jar文件). 或者私服上面也找不到文件,但是引入的中央仓库或者其他公服上面有文件.

解决方案

上面问题往往是在下载依赖过程中网络出现问题导致的.

此时我们本机已经开始下载依赖代码,但是下载失败,本机仓库中会在 MAVENrepo/ M A V E N r e p o / {groupid}/ artifactid/ a r t i f a c t i d / {version} 路径下面生成 *.lastUpdated 的文件.

*.lastUpdated实在可恶,下次再下载时由于它的存在Maven不会再去私服中下载

解决方法:(针对PC与Maven私服之间网络传输问题)

打开本地仓库所在目录, 通过win文件夹的搜索功能,查找 *.lastUpdated ,然后将找到的文件全部删除。

重新 Maven Update Project,若在eclipse中操作时勾选上 Force Update of Snapshots / Releases,若在命令行操作时增加 -U 参数