Eclipse error “Could not find or load main class”

后端 未结 26 1450
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 01:31

I know there are many duplicates of this question, but I have looked at them all, and none of them have solved the issue.

I am trying to run a class that has a main

相关标签:
26条回答
  • 2020-12-07 01:38

    Try to point the classpathentry output path in the .classpath file to target/classes The classpath file is located in the project folder. Edit it manually.

    In my case, it was like this before:

    classpathentry kind="output" path="bin"

    I changed it to:

    classpathentry kind="output" path="target/classes"

    0 讨论(0)
  • 2020-12-07 01:39

    I ran into the same error today, I refactored my project name and then refactored it back to the old name and it ran just fine after that.

    0 讨论(0)
  • 2020-12-07 01:41

    I was also getting same message.That is due to the workspace problem.Create one new workspace and try there once. I think it will works.

    0 讨论(0)
  • 2020-12-07 01:42

    I had the same problem. In my case I did the following, to resolve it.

    1. Select the project in the Eclipse IDE, right click, and open properties dialog.
    2. Select "Java Build Path" item on the left panel of the Properties dialog.
    3. Select the "Libraries" tab, on the right hand panel.
    4. Remove the libraries (jars), which are marked red, or fix the path.
    5. Save the Properties dialog. After removing the "Not found" libraries, Eclipse run/debug started working. The "Not found" message would also show up in the "Problems" pane. which you can open using, Window->Show View->Problems, command sequence. This pane gives you useful messages. The same message might show up for many reasons, other than what I encountered.

    Observation: The classes directory in my case was not created, which means that the javac failed. On command line also, javac works the same way, if you have multiple java files in the same invocation of javac, and one java file encounters a problem, then no class files are created.

    Which means Eclipse puts all the java files in the project with single invocation of javac.

    Now if there are no class files generated, obviously, the message now makes sense. The compile errors are also shown in the "Problems" pane.

    Now this would be the case if there is a compile error. If just a jar file which is not used at all, is on the classpath, there should not be any problem.

    Even if my project had problems, I ignored it, because I was just testing a single class, and was thinking that only that file would get compiled and run, because it was a standalone test, without any dependencies.

    But that is not the case with Eclipse. I wish they did it that way. As you can see lot of people got burnt this way.

    Thanks

    0 讨论(0)
  • 2020-12-07 01:43

    I came across the same problem. You might get this error in many situations like below.

    • Some dependency problem in your pom.xml
    • The run configuration may not have proper configuration. You might want to delete the existing one and create the new one like suggested in other answers.
    • You may want to try like mvn clean, mvn build and other options.
    • You may want to delete the project and import it again.
    • You may want to restart Eclipse and check your luck if it works.

    Here, the list of hit and trial goes on. Believe me the tool Eclipse is not that stupid. It is quite smart to find errors even at compile time. I tried all ways mentioned above, but none worked for me.

    The main problem which worked for me was JRE version which was somehow got set to default (JRE System Library [jre1.5]). I reset it to jre1.8.* which I had installed in my machine.

    I don't commit that this is only the solution to this problem but yes this could be one of the solution. So keep an eye on JRE version.

    0 讨论(0)
  • 2020-12-07 01:44

    I was having the same problem. I was having a maven project. According to my knowledge, it was because i had cleaned the project and there were no class files generated. I did mvn compile and it was started running.

    0 讨论(0)
提交回复
热议问题