maven出现Cannot find the class fil
2018-06-28 本文已影响1人
nextliving
今天遇到一个问题,eclipse中使用STS新建了一个maven项目,但是很多地方报错,具体错误信息是:
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.boot.SpringApplication. Fix the build path then try building this project
根据Spring start project fails in STS with spring boot 1.5.4中的解释,是因为maven解析依赖出了问题。
后来采用的解决方案是,在Terminal中进入项目目录,执行命令$ mvn dependency:purge-local-repository
,终端输出内容如下
MacBookPro:mongodb-springdata-demo chenxin$ mvn dependency:purge-local-repository
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-maven-plugin/1.2.41/kotlin-maven-plugin-1.2.41.pom
......
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/3.0.2/maven-dependency-plugin-3.0.2.jar (163 KB at 302.4 KB/sec)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mongodb-springdata-demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.0.2:purge-local-repository (default-cli) @ mongodb-springdata-demo ---
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-velocity/1.1.7/plexus-velocity-1.1.7.pom
......
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/spring-aop/5.0.7.RELEASE/spring-aop-5.0.7.RELEASE.jar (358 KB at 147.7 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:05 min
[INFO] Finished at: 2018-06-28T09:18:59+08:00
[INFO] Final Memory: 22M/219M
[INFO] ------------------------------------------------------------------------
可以看到下载了很多依赖的jar,之后在eclipse中项目右键->maven->update project,错误消失。如果还是解决不了,可以尝试删除maven本地仓库~/.m2/repository
中的全部内容,然后在eclipse中项目右键->maven->update project