一、问题
今天换了系统,把之前的项目从Gitee
拉取到IDEA
,之后加载Maven
依赖,依赖一片红(之前忘了截图,意思一下)。
然后试过各种方法:改maven
的setting.xml
文件、删除lastupdated
文件、重新下载,都没用。然后我手动删除lastupdated
文件时,提示这个:
二、解决办法
那我就觉得可能是Maven
程序没有读写的权限,然后就百度了一下,修改文件的访问权限:
按照这里的操作走,再删除所有lastupdated
文件,重新加载Maven项目
就好了。
三、清除 lastupdated 文件的方法
1、bat文件
新建文本文件,复制粘贴下面代码,把第一行的文件路径改为你自己的仓库路径,保存,把后缀名改为bat
,双击运行
set REPOSITORY_PATH=E:\Maven\apache-maven-3.6.3-bin\maven-repository
rem -- 正在搜索...
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
del /s /q %%i
)
rem 搜索完毕
pause
2、Java代码,来自:CSDN
https://blog.csdn.net/m0_37138008/article/details/104428616
import java.io.File;
import java.io.IOException;
//列出File的一些常用操作
public class util {
/**
* 遍历指定目录下(包括其子目录)的所有文件,并删除以 lastUpdated 结尾的文件
* @param dir 目录的位置 path
* @throws IOException
*/
public static void listDirectory(File dir) throws IOException {
if (!dir.exists())
throw new IllegalArgumentException("目录:" + dir + "不存在.");
if (!dir.isDirectory()) {
throw new IllegalArgumentException(dir + " 不是目录。");
}
File[] files = dir.listFiles();
if (files != null && files.length > 0) {
for (File file : files) {
if (file.isDirectory())
//递归
listDirectory(file);
else{ // 删除以 lastUpdated 结尾的文件
String fileName = file.getName();
boolean isLastupdated = fileName.toLowerCase().endsWith("lastupdated");
if (isLastupdated){
boolean is_delete = file.delete();
System.out.println("删除的文件名 => " + file.getName() + " || 是否删除成功? ==> " + is_delete);
}
}
}
}
}
public static void main(String[] args) throws IOException {
// 指定maven的本地仓库
listDirectory(new File("E:\\Maven\\apache-maven-3.6.3-bin\\maven-repository"));
}
}