IDEA如何查看日志文件?
有时候是呀idea导入maven项目报错,需要查看具体报错日志。
步骤一:点击工具栏上的 “Help” 选项。
步骤二、 点击“Help”选项后弹出帮助下拉选项菜单,选择 “Show Log in Explorer” 选项。
步骤三、点击 “Show Log in Explorer” 选项后,就可以打开IDEA的日志文件所在的目录了,“idea.log” 就是我们要查看的日志文件。
idea中maven本地仓库有jar包,但还是找不到
1、先看setting maven配置
File -> Settings -> Build、Execution、Deployment -> Build Tools -> Maven
查看maven路径是否指定正确。
2、删除多余资源文件
通过阿里云公共仓库下载的jar,然后放入本地仓库后,无法引用打包报错。因为下载资源后,会生成对应的_remote.repositories文件,标示该资源,删除 _remote.repositories 文件。
递归删除指定目录下指定文件后缀,MavenDeleteVersion:
public class MavenDeleteVersion {
private static List<File> fileList = new ArrayList<>();
public static void main(String[] args) {
//本地仓库地址
String repoPath = "D:\\maven\\repository\\org\\springframework\\cloud";
//需要删除的文件后缀
String[] extensions = new String[]{
"lastUpdated",
"properties",
"repositories"
};
//获取所有文件进行删除
Collection<File> listFiles = listFiles(new File(repoPath), extensions, true);
for (File file : listFiles) {
System.out.println(file);
file.delete();
}
}
/**
* 根据扩展名,过滤文件
*
* @param file
* @param extensions
* @param isDeep
* @return
*/
public static Collection<File> listFiles(File file, String[] extensions, boolean isDeep) {
if (!file.exists()) {
System.out.println("路径不存在:" + file);
}
listFiles(file, extensions);
return fileList;
}
/**
* 根据文件扩展名列表,过滤出指定扩展名的所有文件(包含子目录下的)
*
* @param file
* @param extensions
*/
private static void listFiles(File file, String[] extensions) {
File[] fs = file.listFiles();
for (File f : fs) {
if (f.isDirectory()) {
listFiles(f, extensions);
}
if (f.isFile()) {
for (String extension : extensions) {
if (f.toString().endsWith(extension)) {
fileList.add(f);
}
}
}
}
}
}
然后重新打包就成功了。
3、删除项目下的.iml 文件
如果还不能引用,删除项目下的.iml 文件,然后重新 Reimport All Maven Projects。
4、重新加载项目
如果还不能引用,重新加载项目 File -> Invalidate Caches/Restart
maven打包报错was cached in the local repository, resolution…
这种情况是:之前的中央仓库地址废弃了,本地仓库已经下好了需要的jar包。然后,中央仓库换成阿里云的之后,用maven打包的时候报错了,因为阿里云仓库恰好没有该jar包。各种clean 、install都无济于事,大概的错误如下:
Failure to find org.springframework.cloud:spring-cloud-consul:pom:1.1.0.TSF-RELEASE in http://mirrors.cloud.tencent.com/nexus/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of tsf has elapsed or updates are forced
中文翻译:
已缓存在本地存储库中,在tsf的更新间隔结束或强制更新之前,不会重新尝试解析。
解决方法一:pom.xml配置多个远程仓库地址
<repositories>
<repository>
<id>tsf</id>
<url>http://mirrors.cloud.tencent.com/nexus/repository/maven-public/</url>
</repository>
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</repository>
</repositories>
解决方法二:使用本地nexus仓库
新建本地nexus仓库,将需要的jar包统一下载管理,就不会存在多个远程仓库访问问题,而且便于维护。
解决方法三:idea的maven项目引入外部jar包
具体步骤参见:《Intellij IDEA在maven项目中添加外部Jar包运行》