Reputation: 2578
I have a main method in a package in one of my projects. Say, the package is com.ant.car
. I am trying to run and/or debug this main method, and I keep getting the error Could not find or load main class com.ant.car
.
I've searched this problem, and it seems like I can't figure out what is wrong.
1) I've checked run configurations. In Run->Run Configurations, I've checked that the Main class is com.ant.car.
2) I've checked build path. If I right click on the project, I select Build->Build Path, and under the Libraries tab I make sure there are no missing folders with red Xs next to them.
Not really sure what else to do. Any suggestions?
Upvotes: 8
Views: 60318
Reputation: 1
You just have to follow the below steps;
This will help in the resolving the error.
Upvotes: 0
Reputation: 720
I had this problem on eclipse sts. For me the following steps solved the problem.
In Boot Dashboard > left click in your project > Open Config > fill the "Main Type" with your main application.
Upvotes: 1
Reputation: 11
I tried all the answers but finally what worked for me was deleting the project from eclipse workspace and importing it again.
Upvotes: 1
Reputation: 108
You can try one of the two solutions below: Solution 1: Right click the project -> Gradle -> Refresh Gradle Project.
Solution 2: Add gradle or maven in your environment variable. My problem was that I had not added gradle in my environment variable. Before, make sure Gradle or maven is installed in your OS.
Upvotes: 0
Reputation: 65
You just need to delete Run Configuration file and restart STS and run command -mvn clean install and try to restart the service
Upvotes: 1
Reputation: 1
Upvotes: 0
Reputation: 1400
This worked for me to solve the error. (I got this error after removing AWS ToolKit)
Upvotes: 0
Reputation: 1
I spent several hours on this issue, finally it is fixed by doing this: Properties -> Java Compiler: uncheck the checkbox "use '--release' option"
Upvotes: 0
Reputation: 542
A quick and easy fix is to directly run your SpringBootApplication class (i.e. Right click, Run As -> Spring Boot App). This runs the app and creates a run configuration automatically.
Upvotes: 0
Reputation: 506
It worked for me:
1. Delete metadata from work-space directory.
2. Import the project again, but selected copy to work-space option.
I think the cause for the error was Non-English characters in the original saved directory.
Upvotes: 1
Reputation: 21
Deleting target folder manually and mvn clean install worked for me
Upvotes: 0
Reputation: 81
Try updating project by right clicking on it. Maven -> Update Project
Upvotes: 8
Reputation: 31
This issue occurs when the main .class file moved or not found because you changed the directory for committed/shared the project into the git or another repository.
To Resolve this issue --> Remove existing run configuration and new one. Find the parent pom.xml or project pom.xml and open cmd/command prompt and run the below commands,
Upvotes: 1
Reputation: 3323
1 ) Clean the Project
2 ) Enable build automatically Option
3 ) Update the maven project by use the short cut Alt + F5
Upvotes: 0
Reputation: 71
What worked for me: Menu Project -> Properties In Java Build Path, tab Libraries Delete all libraries with a red [x] next to them.
In my case, problem happened when I switched from Kepler to STS IDE.
Upvotes: 5
Reputation: 76
Today I ran into the same problem and I tried a lot of answers. Nothing helped. Cleaning the project, build automatically is already checked, deleting .metadata
, etc.
Eventually I tried this and it worked perfectly:
menu Project -> Properties
Java Build Path, tab Libraries
Remove the JRE System Library from there, press Add Library
, take the JRE System Library and press Next
. Workspace default JRE
and press Finish
.
Upvotes: 6
Reputation: 44
Project -> Clean... -> check project not working -> Clean
I already had build automatically set, but forcing STS to rebuild it fixed it.
Upvotes: 1
Reputation: 1
I think .class files are deleted/missing from JavaProject/bin folder.
To resolve this issue ->
1) Just cut paste and save the code contents of all the files that you are using then .class files will be regenerated.
2) Then run the code and you can see it works fine if there is no syntactical errors.
Upvotes: 0
Reputation: 1
I faced the same issue..
just do follow these steps:
STS/Eclipse --> 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.
Upvotes: 0
Reputation: 83
Sometimes the problem can be caused by some newly added dependencies. Try removing the recently added jars. That's how I fixed my problem.
Upvotes: 1
Reputation: 2578
The solution to this was the following:
.metadata
directory (or to be safe, copy the directory somewhere else to be safe, then delete it)Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.
Upvotes: 1
Reputation: 56
The Error "Could not find or load main class com.ant.car" occur when your class is not in build path. please make sure that .class file is generated and it's in build path ..
Upvotes: 0