.lastUpdated文件产生原因:
maven仓库中的某个构件如果因为网络或者其他的原因,没有下载成功或者下载被中断,将会出现一个LastUpdated的文件,这个时候,就算网络好了,也不能正常使用这个构件 ,需要将.lastUpdated文件删除掉.
删除.lastUpdated文件
- windows系统
cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i
- linux系统
find /app/maven/localRepository -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;
探究.lastUpdated文件删除不掉的原因
在使用idea离线导入maven仓库的时候总是提示jar文件导入不成功的错误,后经过分析,发现不成功的文件夹里面存在.lastUpdated
后缀名的文件,删除该文件也未曾生效,依然会重新生成,后经过分析_remote.repositories
文件,发现如下的情况
junit-3.8.1.pom>nexus=
junit-3.8.1.jar>nexus=
junit-3.8.1.jar>central=
junit-3.8.1.pom>central=
maven的setting.xml配置如下
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<name>nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
id取值详解
– public 本地仓库
– nexus 私服
– central 中心仓库
jar包查找顺序
本地仓库(本机)—>私服(局域网)—>中心仓库(外部网络)
通过我测试发现,我设置aliyun仓库的时候,会更新_remote.repositories为如下内容
junit-3.8.1.pom>nexus=
junit-3.8.1.jar>nexus=
如果我将aliyun仓库注释掉,默认使用外网maven仓库,此时_remote.repositories为如下内容
junit-3.8.1.pom>nexus=
junit-3.8.1.jar>nexus=
junit-3.8.1.jar>central=
junit-3.8.1.pom>central=
原来每次在更新maven项目的时候,每一个jar包路径下的_remote.repositories
文件都会同setting.xml中设置的仓库地址id进行判断,如果没有匹配,会自动更新该jar包的相关文件,如果未联网则会出现jar无法发现的错误,导致即使jar存在,maven项目也无法使用该jar的情况。如果使用公司的内网仓库_remote.repositories
文件变为_maven.repositories
。
最后,附上删除lastupdated脚本文件
1、cleanLastUpdated.bat(windows版本)
@echo off
rem create by NettQun
rem 这里写你的仓库路径
set REPOSITORY_PATH=D:\Java\maven-repository\maven-aliyun\repository
rem 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
del /s /q %%i
)
rem 搜索完毕
pause
2、cleanLastUpdated.sh(linux版本)
# create by NettQun
# 这里写你的仓库路径
REPOSITORY_PATH=~/Documents/tools/repository
echo 正在搜索...
find $REPOSITORY_PATH -name "*lastUpdated*" | xargs rm -fr
echo 搜索完
评论前必须登录!
注册