简体   繁体   中英

Error: Could not find or load main class in Spring STS for Spring BOOT project

Tried cleaning projects and giving multiple builds but I am getting "Error: Could not find or load main class".

  • I changed STS workspace
  • I have given maven build
  • No such compilation error
  • JDK 8 installed in my machine

But I am getting the error when I am running Application.java class

Please help me out.

I faced the same issue..

just do follow these steps:

STS --> Project --> Enable "Build Automatically"

then refresh your project, it will resolve your issue.

Still not refreshed your projects automatically, just restart your STS and check.

Hope it will help you. Happy reading.!!!

Look at the problems tab and see some of the jars under .m2 might be complaining. In my case spring-boot-autoconfigure jar was a problem.

navigated to user C:\\Users[your user].m2\\repository\\org\\springframework\\boot

renamed folder spring-boot-autoconfigure

right click on project go to maven

click update

and problem disappears

some solutions suggest that the main class not found problem occurs due to any conflicting jar or corrupted jar file which is true but unfortunately as long as I found they suggest to remove .m2 folder altogether. Though it may resolve the issue but is time consuming because all the dependencies will be re-downloaded.

That's why I was running after to find where is the root cause and problems tab which appears along side the console tab in STS and Eclipse helps.

  1. In short stop IDE
  2. either remove .m2 folder or remove specific dependencies under .m2 if you know which is problematic.
  3. restart
  4. IDE right click project and maven update

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM